lua-users home
lua-l archive

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


On Sun, Jul 4, 2010 at 06:29, Vaughan McAlley <vaughan@mcalley.net.au> wrote:
> On 4 July 2010 12:50, KHMan <keinhong@gmail.com> wrote:
>>
>> An impossible social issue to settle, I rather think, since the range of
>> skills is very wide. Like many Perl users, I can only type away on a
>> keyboard in a subset of Perl, so that's one unintended way of allowing
>> beginner and expert use to coexist. Can one say I am using precisely the
>> same Perl? Maybe not, since I am practising TIMTOWTDI without any skills to
>> code in "other ways". This would also not work with a small fat-free
>> language.
>>
>>
>
> Looking back at my first Warcraft addon, there are a few locals within
> functions, but every other variable was a (mostly) distinctively named
> global. Performance was fine. I was able to learn and get to like Lua
> before grasping the subtleties of lexical scoping, which I personally
> appeciate- friendly for beginners and powerful for advanced users.
>
> Vaughan
>

I doubt you'd see a noticeable performance hit from using globals,
except perhaps in extremely CPU-intense scripts that are doing a lot
of calculations (in which case you may want to move those functions to
a C module). The real issues as I see it are polluting the namespace
and not keeping your code self-contained. If your module is using a
bunch of globals, you have the potential for name conflicts, possible
security issues (one script "breaks into" a more privileged script by
messing with its state), and other bugs.

Generally, a module should define/return a single global table
containing all of their functions, constants etc. Of course, there are
exceptions to every rule.

-- 
Sent from my toaster.