[Nickle] Pragma to enforce unique variable names in each scope?

David M Guy guyd at cs.pdx.edu
Thu Nov 13 12:28:46 PST 2003

I agree that a special keyword for each variable name that you want to be
unique in each scope seems unwieldy, especially since an anal programmer
like myself would feel compelled to designate EVERY variable as 'unique'.

As for the 'i'-variable in this 'for' loop example, I think most
programmers (especially C-programmers) will habitually use the initializer
expression of the 'for' loop to reset the variable. If they don't, they
either forgot (not very likely) or they intended to use the previous value
as the initial value (far more likely).  I don't see how it could be a
good idea to redeclare your loop variable every time you use a 'for' loop
(unless you use the C++ version which allows you to declare a loop-scoped
variable in the initializer expression).

Are there other situations where this would be useful for other than
globally scoped variables?

 - David Guy

On Thu, 13 Nov 2003, Keith Packard wrote:
> However, there are legitimate uses for repeated definitions at local scope:
> 	int i;
> 	for (i = 0; i < 10; i++)
> 		...
> 	if (i < 5)
> 		...
> 	int i;
> 	...
> The goal here is to permit the redefinition so that you don't reuse 'i' in
> a similar but not identical fashion (like indexing two different arrays).
> By allowing the redefinition, we assert that each 'i' is actually
> separate, and unrelated to any 'i' above in the program.
> I know this isn't consistent with C which requires all declarations to
> occur at the begining of the function, but I think it's less error prone
> and makes maintaining the code easier as declarations and code are
> held together in a single block.
> I don't see the practical utility of requiring a new keyword for every
> declaration to change this behaviour though; it's just noise most of the
> time, obscuring the real program.

More information about the Nickle mailing list