lua-users home
lua-l archive

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




On Saturday, August 9, 2014, Axel Kittenberger <axkibe@gmail.com> wrote:
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
>



"Stupid" was an unfortunate choice of words. 

An important use case for Lua is as a configuration language:

window_height = 800
user_name = "Sally"

----


That's the entire program. In fact, Lua is anything but terse, lacking many sugary treats like "x++" and using "do / end" instead of "{}". 

As is often the case when something looks"stupid", especially something as refined and meticulously curated as Lua, it's a good idea to question your own perspective, before publicly condemning it. 

Of course, you are free to disagree. Please don't be disagreeable when you do it. 

-Andrew