lua-users home
lua-l archive

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


Petri Häkkinen wrote:
On 7.8.2010, at 6.10, Mark Hamburg <mark@grubmah.com> wrote:

-- Define a module with functions foo and baz:

local M = { }

function M.foo()
   --
end

function M.baz()
   --
end

return M


This hardly seems particularly bizarre and it doesn't rely on tricks with environment to change global assignments into exported values.

Mark


Indeed. Honestly this should become the recommended practice or the new 'policy', if you will. It's as explicit and simple as it gets. Although it takes a bit more typing because you'll need to prefix function calls inside the module with 'M.' But I actually like it that way because it's clear where those function calls lead to.

Petri

Hurrah,

A vote for true simplicity and explicit scope control. At the cost of those few extra keystrokes, almost every part of lua programming could be made more clear. Unfortunately, without the enforcement of something like "module", this, like every other simple and beautiful approach, will grow bat wings, a tail, and whatever other things that can be imagined by various authors.

Explicit prefixing prevents the most unobvious effects of changing environments on the fly, when a variable or function suddenly changes entirely before our eyes. For those too lazy to do such prefixing, I would trot out a quote from an old buddy of mine. "Flexibility is nice, but did you ever try to sit in a truly flexible chair." 

Everett L.(Rett) Williams II