lua-users home
lua-l archive

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


Yes, it has been hughly debated.
http://lua-users.org/wiki/LocalByDefault

I personally feel implicit anything by default is a stupid idea, since for somebody doing a project beyond the simple quick&dirty hack thats only ran once, typing a few chars more always compensates for a long debugging session, but oh well. Unfortunally languages are still often compared. debated and evaluated with "look I can do the same thing with even less characters, my language is cooler!"


On Fri, Aug 8, 2014 at 9:49 PM, Steven Degutis <sbdegutis@gmail.com> wrote:
I'd love to hear more about how "local by default is a mess". Is there
anything written on this topic regarding Lua?

On Thu, Aug 7, 2014 at 12:06 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> So recently I found out that local variables are always faster. So I
>> have two questions, when would you ever need a global variable, and
>> why would Lua make all variables global by default if you use local
>> way more often? It seems to me that I could just declare a variable
>> local right off the bat so it has the same scope as if it were global
>> (I feel like there has to be a difference in scope that I just don’t
>> know about).
>
> 1) Local by default is a mess.
>
> 2) You do use a lot of globals in Lua. If you write
>
>   print(string.len(str))    --<< 'str' is a local variable
>
> you are using two globals and one local.
>
> -- Roberto
>