Re: identifiers and modules
- From: "Rob Thorpe" <robert.thorpe@xxxxxxxxxxxx>
- Date: 3 Jan 2006 02:15:23 -0800
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.
:)
.
- References:
- Re: identifiers and modules
- From: Per Bothner
- Re: identifiers and modules
- From: Ulrich Hobelmann
- Re: identifiers and modules
- From: Per Bothner
- Re: identifiers and modules
- Prev by Date: Re: Beyond ascii
- Next by Date: Re: Declaring procedures
- Previous by thread: Re: identifiers and modules
- Next by thread: Re: identifiers and modules
- Index(es):
Relevant Pages
|