Re: identifiers and modules



Per Bothner wrote:
> Ulrich Hobelmann wrote:
> > I did that in C more than once, and ran into problems with Java.
> > Sometimes I have an if-statement, inside it a for (using "i"). Later
> > another if and another for, but then I get the message that i is already
> > used. Not sure if this was the problem, maybe there was real shadowing
> > of outer bindings -- I suppose there was. But I don't see a reason why
> > I should for instance change some local loop variable from "i" to "ii"
> > or something that makes me more likely to produce subtle errors, when
> > all I want is a new local variable.
>
> If the loops are inside each other, then you *should* use different loop
> names. If the loops are not nested, then the loop variable scopes do
> not intersect, then you can re-use the same name, so no problem.
>
> Do you really think allowing somebody to write
>
> (do ((i ...)) ...
> (do ((i ...) ...))
>
> is useful? Which do you think is more likely: The programmer
> made a mistake or that the program really does what was intended?

I've seen code before that does that, I doubt it's uncommon.

The difference of opinion probably relates to how different programmer
code. If I'm writing a long function with many variables I will name
them systematically according to what they do. Things like
"x-axis-zoom-factor" or "pixels-per-metre". Some people write short
names like "x" and "ppm", I find this difficult to understand in long
functions. I still call iteration variables "n" or "m". In a long
function I will use different names for all the iteration variables
that are different. In this case I would not care if the language
didn't allow reuse of names. It would not help me much, but it might
help those who use short names for everything.

The problem is in reusing code. If I copy a piece of code from
elsewhere into somewhere else I expect it to work. It doesn't seem
reasonable to me that I have to plough through it changing variable
names just because the compiler says I must.

It also makes use of code as data more difficult. If the programmer
wants to expand a macro textually then it becomes more difficult to do
so. It also becomes more difficult to auto-generate code.

I think a warning would be useful, but an error is counterproductive.

> I *am* arrogant enough to put my judgment over the user.

:)

.



Relevant Pages

  • Re: Value of inheritance in Object-oriented programming
    ... Timofei Shatrov wrote: ... which has no control flow constructs at all: all ifs and switches ... How do you make loops? ... which can do entirely different things if the programmer wants it. ...
    (rec.games.roguelike.development)
  • Re: Total Common Numbers
    ... I am not a programmer but have looked through the code that you have ... two different lists and tallying the appropreate results is. ... it would be best to use a smaller pool of numbers. ... agrees with the value you posted from your loops. ...
    (microsoft.public.vb.general.discussion)
  • Re: looking for thoughts on the philosophy of optimizing compilers
    ... the compiler removes it entirely. ... On most processors there should be a clock cycle counter or timestamp ... that sometimes you need such loops, ... A human programmer should investigate ...
    (comp.lang.c)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... )> these choices the language makes, as long as the choice is clearly ... and as long as the programmer knows which choice was made. ... for loops don't necessarily need to run over a row ... You all think I'm paranoid, ...
    (comp.programming)