[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Making vars local by default
- From: "Russell Y. Webb" <rw20@...>
- Date: Tue, 22 May 2001 13:35:14 -0700
> It's starting to become apparent to me that life would be easier if new
> variables were
> local by default, instead of global.
I too have wished for this (as have several others). The main problem is
code compatibility and the perception that global-by-default fits better
with Lua's role as a configuration language (in conflict with its role as a
Here's a thought. How about introducing the key work "global" that for now
does nothing (since that's the default behavior). That means that new code
can be written with explicit "global" notation (making it clearer in my
estimation) and opens the possibility of having a code base one day that
could without too much pain transition to a local by default rule (though it
might not ever switch over). Code written entirely in this new style could
run in a modified Lua for those who think that's a feature. Of course this
new code will not run on old versions of Lua but that's often true with
changes to Lua (like the for loop constructs).
Another route is to disallow assignment to globals without passing through a
function: global("name", new_value). This can be done today and aside from
making standard Lua code fail its only problem lies in the strange feeling
syntax, but who really needs to write to globals very often anyway?