lua-users home
lua-l archive

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


On Sat, Aug 7, 2010 at 4:43 PM, Everett L Williams II
<rett@classicnet.net> wrote:
> The thing that is important here is whether it is ambiguous to the poor
> guy who must read or write this stuff.

I don't disagree.  There are two separate questions here: (1) how to
make environments work well for module definition and (2) whether
environments are worth it even given an optimal solution for #1.

In comparison, C++ does mix some namespaces, but many style guides
recommend undoing that by using a limited form of Hungarian notation
to differentiate variable scopes:

  void setx(int x) { m_x = x; ms_counter++; }
  // method where x is parameter, m_x is instance member, and
ms_counter is class member

(True, an editor could help in the differentiation with syntax
highlighting, but C++ is hard to parse, and `m_x = x` could be
rewritten `this->x = x`.)

In Lua, there have been many suggestions to use environments in module
definition, and this has continued in the 5.2 discussions.  I don't
think the idea is that unreasonable since something like this

  function foo() baz() end
  function baz() print(x) end

doesn't seem inherently that unclear, any more than

  local foo, baz
  function foo() baz() end
  function baz() print(x) end

_unless_ you're creating a module member whose name conflicts with a
global because then it does become ambiguous.  debug.debug() is one
such example :)  and is one good reason that perhaps the answer to #2
is no.