lua-users home
lua-l archive

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


On Mon, Mar 31, 2014 at 11:41 AM, Peter Melnichenko
<petjamelnik@yandex.ru> wrote:
> I'm wondering what is the current policy on localizing globals in modules(e.g. `local type = type; local tinsert = table.insert` etc). I never did it before because the performance gains were usually negligible, but there was a point raised that it should be done to protect modules against monkey-patching.

Key word is 'usually' ;)   So then it seems like premature
optimization to localize all globals?

I've fallen into the habit of doing this - it does document what
libraries a module uses, although a little ... tedious to type.
(Little macros can be written if you use a clever editor)

As for monkey-patching, as a community we don't like it much,
particularly for public-facing modules.  It has caused great grief to
the Rubyists...who would be so mad as to redefine 'table.insert'?