lua-users home
lua-l archive

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

It was thus said that the Great Daurnimator once stated:
> Additionally, your code is only 5 lines of code that sets a global
> object's metatable....
> I'm not sure why this is something that deserves to be its own module.

  A short module can have valid semantic meaning that belies the trivialness
of the module (leftpad notwithstanding [1]).  I have several private modules
that are very short.  For instance, I have this one (org.flummux.editor

	local sys = require "org.conman.sys"
	local os  = require "os"
	return os.getenv("VISUAL")
	    or os.getenv("EDITOR")
	    or "/bin/vi"

  And another one that implements the Y-combinator in Lua (org.flummux.Y)

	return function(f)
	  local function g(...) return f(g,...) end
	  return g

  I also have several other ones that consist of a single function (but are
longer than a few lines.  I'm still debating how I feel about this---on the
one hand, writing such hperfocused modules allows one to just include what
is needed and prevent a much larger attack surface for exploits.  It also
prevents a module with a mishmash of functionality from being created.

  On the other hand, it does seem strange to have a module of a few lines.



[2]	Yes, I even namespace my own private modules.  The modules under the
	org.flummux domain are experimental, yet to be published modules.

[3]	Basically, this allows you to do recursion with an anonymous