lua-users home
lua-l archive

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


In an interactive environment, you want explicit globals because you are
likely to execute code a little bit at a time.

When compiling scripts, they are less desirable and globals are frequently a
performance lose. But note that anything that relies on something like "_G"
is depending on an implicit global.

On the other hand, as various people have pointed out local-by-default is
difficult to make work reliably and predictably because sometimes you need a
declaration outside a particular scope and sometimes you don't.

At the expense of another keyword, the above points probably would argue for
having a keyword "global" and an option to compile code such that undeclared
variables are treated as errors.

Is the change worthwhile? I'm unconvinced. Our experience on Lightroom says
there are plenty of ways to work around it through enhanced tools. It could
have the benefit of encouraging people to cache globals into locals if the
syntax went beyond global declarations and were friendly to such caching but
I don't know what that syntax would look like. (On the other hand, I've got
one file in Lightroom that is blowing out the local limit right now which
results in rather cryptic compilation failures.)

Mark