lua-users home
lua-l archive

RE: local by default

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


David Given wrote:
> Matt Campbell wrote:
> [...]
> > What is the position of the Lua team on making variables local by 
> > default when they are assigned within a function without being 
> > explicitly declared? Is the team considering this change 
> for a future 
> > version of Lua, or will the "local" keyword always be 
> required? Also, 
> > are any local-by-default patches available for Lua 5.x? Thanks.
> 
> This shows up periodically on the list. I am not a member of 
> the team, but I believe the general consensus is that it's 
> not a good idea, because:
> 
> function increment_i()
> i = i + 1 -- this doesn't do what you expect
> end
> 
> But if you want the full discussion, I'd suggest checking out 
> the list archives.
There has been a few good explanations in that topic iirc (check
preceding and following posts, that one has some particularly
interesting quotes):
http://lua-users.org/lists/lua-l/2006-09/msg00103.html
I remember that the conclusion was something like: global by default is
bad, local by default is much worse.

AltStyle によって変換されたページ (->オリジナル) /