lua-users home
lua-l archive

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


2014-04-14 11:03 GMT+02:00 Enrique Garcia Cota <kikito@gmail.com>:

> I've written a series of articles about building Lua modules - it's here:
>
> http://kiki.to/blog/2014/03/30/a-guide-to-building-lua-modules/
>
> I would appreciate any feedback or comments on it.

Rule #1: Do what Lua does
   Agree 95%. The exception is table.insert, which violates the
   rule "One thing, and one thing only". As a consequence,
   table.insert(tbl,j,nil) and table.insert(tbl,j) do not mean the same.

   Your article could add: supply concise but precise documentation.

Rule #2: Always return a local table
   Agree 95%. The exception is when all that the module does is
   some monkeypatching :-)

Rule #3: Allow monkeypatching
   Agree 5%. No monkeypatching should be the default, and
   it should be documented clearly when a module allows it.
   Efficiency is not the only reason for caching system functions
   locally, and designing module functions to be definable abstractly
   is not all that easy.

Rule #4: Make stateless modules
   Agree 80%. The exceptions involve modules that are designed
   to be used preloaded in interactive sessions.

Rule #5: Beware of multiple files
   Agree 95%. The exception is when the module requires
   a module from the cpath.

Rule #6: Break the rules
    Agree 100%, when qualified by "but say why".