|
But in Lua 5.2 the way globals are handled are much prettier than its peer languages.
I typed "globals" and my phone corrected it to "globalism", which is a clever name for a particular style of coding....
This is not really specific to Lua, it's a general programming
concept. Variables should be limited to the scope in which they're
needed. Almost all variables you create are probably going to be
locals. But every "built-in" function you're using is just a global
variable. Only create globals when you need information to be shared
between modules and if this is the most practical way of doing so
(it's usually not but sometimes it is).
On Thu, Aug 7, 2014 at 12:18 PM, Mason Mackaman <masondeanm@aol.com> wrote:
> So could I have an example of where one would want or need to declare a global variable?
> On Aug 7, 2014, at 12:05 PM, Elias Barrionovo <elias.tandel@gmail.com> wrote:
>
>> On Thu, Aug 7, 2014 at 2:02 PM, Coda Highland <chighland@gmail.com> wrote:
>>> But you're exactly right -- you could do that, and many people DO
>>> exactly that as an optimization.
>>
>> More than that; it's generally considered a bad habbit to use globals,
>> especially when creating libraries, or otherwise there's a good chance
>> there will be name conflicts.
>>
>> Now why lua variables are global by default is something that shows up
>> quite often here on the mailing list. If you search the lua-l archives
>> you'll se a lot of discussion about that. Key search terms would be
>> "global by defaul", "local by default" and "lexical scoping".
>>
>> --
>> NI!
>>
>> () - www.asciiribbon.org
>> /\ - ascii ribbon campaign against html e-mail and proprietary attachments
>>
>
>