lua-users home
lua-l archive

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


Hi all!
Sorry for cross-posting from scite-interest, but since I "let myself go" in a recent post there (replying to Steve Donovan, before I saw this thread) about this same topic, I will copy and paste my two eurocent from there (and add a bit more) :-) .

<cross-post>
I'm not an extremist about globals (regardless of language), but I still try to avoid them like plague, except for quick and dirty throw-away scripts/programs. In the years I've grown a sort of itch about them: whenever the code I'm writing grows longer than, say, about 20-30 lines, I feel an urge to make any symbol "as local as possible" :-) . For the same reason I feel rather disturbed when external code has "unexpected" side effects (well, with Lua modules this is not so "unexpected"... :-) ). I highly value the principle of least surprise and unknown globals popping up from almost nowhere is not something I would want to care about! I'm not really an expert of Lua, but I don't see the _need_ for a module to make its "symbols" directly accessible as globals (or as a global table). It's Just a convenience, but if the module returned the "symbol" table (as you point out [Steve D.]), there would be no need to put anything in _G (or am I missing something?!?). This is maybe more troublesome with modules loaded indirectly: in this case I may not even know that something is being put in _G (the module I require might behave "nicely", but require in turn another module that doesn't)!
</cross-post>

Therefore I welcome the upcoming change in 5.2 (_ENV, module deprecation, etc.), but I admit that devising a clear protocol for modules definition (as many have pointed out recently on this list) is something that IMHO should be done. I know (and like) Lua's policy of providing mechanisms instead of mandating practices, but at least a common "endorsed" convention on module definitions could help code reuse and maybe Lua diffusion. In this respect, whereas I appreciate Lua minimalism, I think that an endorsed standard for modules could make more libraries "play nice" to each other and so help establish a community-driven "standard libraries collection" (IIRC there was a thread about this some months ago).


Best Regards,
Lorenzo