lua-users home
lua-l archive

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


On Mon, Apr 15, 2013 at 8:38 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
The attitude (the term 'prejudice' almost sneaked out, but I bit it back)
is illustrated most clearly by the pejorative term "polluting the global
namespace".

It is a particularly painful prejudice in the C++ universe; there was a near-riot when one of the leading lights wrote this line:

using namespace std; // so sue me
 
   1. Don't make it local if you plan exporting it, but define it inside
      its table to begin with.

That's a simple enough rule, although of course the table itself might be local.  

   2. Make it global if it is used so often that it almost feels
      as if it is part of the language.

Here we have one of those 'beauty is in the eye of the beholder' things.  Since everyone's taste and priorities differ, then using such libraries ends up leaving _G cluttered.  By all means provide a way to inject globals (I use pl.utils.import for this) but one has to respect the Lua state of one's users.  In particular, what's convenient in interactive shells is a special but important case.

I do agree that pushing the 'correct way' is unnecessary pedantry, especially for newcomers and 'casual' scripters as Vadim says. Sometimes bicycles need training wheels.

There is a non-ideological use of local on the module level, which is for optimization. Then Knuth's remark always applies ;)