lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

2000-05-02-19:53:16 Edgar Toernig:
> - Another thing with for-loops.  Why did you to made the iteration
> variable an automatic local?  I considered this while implementing
> for-loops for 3.2 but discarded that idea pretty fast.  It's too ...
> inconsistent!?! ... special? ... ugly!  Look at this:
> 	n="foo"				-- global n
> 	print(n)			-- foo
> 	for n=1,3 do print(n) end	-- 1 2 3
> 	print(n)			-- foo
> Ok, sometimes it may be easier to not have to write the "local n" and
> the generated code saves one instruction but it looks so ... wrong.

Interesting. I think it's fascinating that you dislike this; it
suggests that there's some basic difference in our programming
backgrounds or something. I really like having the iterator variable
for a loop construct be automatically local to that loop. Using the
same variable as a global and a loop counter is sorta tacky looking,
I probably wouldn't usually do that, but using a common variable
name like "i" for a loop index is a comfortable style, and I like
the feature that you can keep doing it as you nest loops, only
switching to distinct loop variable names of you expressly want the
outer loop's index to be accessible within the inner loop.

> - About the break I have to repeat myself:  I don't like the concept
> of break-labels.  If you want labels, add a goto but not a break.
> If you want a multi level break, use break-levels.  Sorry.

Another interesting one. I much prefer breaks with labelled blocks
(e.g. perl) over counted break levels (e.g. /bin/sh) or gotos.
Breaks are more constrained than gotos, it's more immediately
obvious to me what control flow is happening.