lua-users home
lua-l archive

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


On Wed, Oct 19, 2011 at 6:28 AM, Tony Finch <dot@dotat.at> wrote:
> Hisham <hisham.hm@gmail.com> wrote:
>>
>> For that reason, I think #5 produces the clearest programming idiom.
>> Distinguishing private and public functions with "local function" and
>> "function" is very logical, if you think of "module" abstractly, as a
>> language feature.
>
> One of the key goals of 5.2 is to put Lua's scoping on a more solid
> conceptual foundation. Getting rid of setfenv except as a dirty debugging
> feature is a key part of that.
>
> Luiz's module pattern gives you 'local function foo" for private functions
> and "function module.bar" for exported ones.

But having to write "module.bar" (or "M.bar", or "_M.bar"...) in every
use of module functions within the module is cumbersome. Someone might
argue that it "documents" the code, but that's only in the same sense
that Hungarian notation documents the code. If I decide to make a
function public I'd have to scan for all references to it and add
"module." or "M", or "_M"...

The alternative of having an "exports table" in the bottom with
"return { foo = foo, bar = bar, ... }" is a throwback to the
duplicated-declarations world of .c and .h files, except that at least
in C you can easily spot that a function declaration is private or
public through "static"; with the "exports table" one would have to
check back and forth at the bottom of the source file.

None of them are as clean as the programming style with module().

-- Hisham