On Fri, Aug 8, 2014 at 12:49 PM, Steven Degutis
<sbdegutis@gmail.com> wrote:
I'd
love to hear more about how "local by default is a mess".
As Jorge already noted in this thread, "local by default" only
makes sense if all variables
must be explicitly
declared. If you haven't got that property, then you can't
locally hide variables declared in prior scopes, which makes for
incredibly fragile code.
Since Lua already requires local variables to be
declared, there's really not much to change. The only thing
that could really be changed is either requiring global variables
to also be explicitly declared, or forcing them to
be identified as global with some operator-like prefix or a
naming convention. But that's different from "local by
default" - that's "there are no defaults".
Incidentally, Lua's globals are actually implemented as
locals, since a reference to a global variable is just
syntactic sugar for _ENV["variablename"],
where _ENV is a
language-defined local variable which the runtime
initializes for you with the table of globals. (And yes,
it's a real local, you can shadow it or reassign it like any
other variable, and all "global" access from that point on
will go through whatever value you change it to.)