lua-users home
lua-l archive

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

On Feb 16, 2010, at 4:42 PM, Matthew Wild wrote:
> I don't find this confusing at all, it's perfectly logical. But
> jumping over local statements and then having the variable magically
> exist is logically wrong :)

The variable already exists.  The 'continue' just jumps into code that can see the variable.

Implementing 'goto', including jumps into blocks, might require implicitly entering blocks and 'magically' creating variables.  But lexical scoping (together with a default value rule) makes the implied behavior precisely defined and logically consistent.

You can see something similar in C, except that C unfortunately does not define a default value for unassigned variables.  This made sense given the compiler state of the art in 1970.  No one wanted the compiler to generate redundant instructions in the cases where it is not smart enough to recognize the default initialization as unnecessary.  But we've evolved to a state where this is a bit amusing.  Since undefined variable bugs are by nature non-deterministic and extremely nasty to debug, there's a broad consensus that compilers should complain noisily when they think a variable might be used before it is initialized.  So now we have compilers forcing the *programmer* to write redundant code in those cases when the compiler is not smart enough to recognize the initialization as unnecessary.