lua-users home
lua-l archive

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


On Sun, Feb 28, 2016 at 8:42 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2016-02-28 1:02 GMT+02:00 Sean Conner <sean@conman.org>:
>> 2) But it does mean that when I'm doing a heavy POSIX program, it's a lot
>> of:
>>
>>         local process = require "org.conman.process" -- fork(), etc
>>         local signal  = require "org.conman.signal"  -- signals
>>         local getopt  = require "org.conman.getopt"  -- parse command line
>>         local syslog  = require "org.conman.syslog"  -- syslog
>>         local errno   = require "org.conman.errno"   -- defines for errors
>>         local fsys    = require "org.conman.fsys"    -- file system calls
>>         local net     = require "org.conman.net"     -- network code
>>         local sys     = require "org.conman.sys"     -- um ... [2]
>
> This can obviously be done in a loop, or by a single function call
>     import"process signal getopt syslog errno fsys net sys"
>  if you did not 'local' all those names. After all, you are probably
> going to follow all that with `local fork = process.fork` etc for the
> particular functions you actually need.

I would create module "org.conman" and use it in the following way:\

local conman = require "org.conman"
conman.process.fork(...)
conman.getopt.foo(...)
etc

Just one local variable.

> I wonder if the dogma of "Don't pollute the global namespace"
> is not being clung to too religiously. In this sort of situation, where
> the names are those of near-standard libraries (at least within
> conman.org), I think there is something to be said for keeping them
> in _ENV.
>

"Don't pollute the global namespace" **must** be followed in
libraries, but it needs not to be followed in tools. Because polluted
code from libraries will pollute all code of other libraries and tools
using the library.

Anyway using debug.smth to pollute the local namespace (as discussed
below in this thread) is even worse than polluting global namespace.
The global namespace was created to be polluted and the locals were
created to keep things clear.

-- 


Best regards,
Boris Nagaev