[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Local Variables
- From: Steven Degutis <sbdegutis@...>
- Date: Fri, 8 Aug 2014 14:49:14 -0500
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
>