lua-users home
lua-l archive

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


On 21 Nov 2013, at 22:41, Craig Barnes <craigbarnes85@gmail.com> wrote:

> On 21 November 2013 22:32, Kevin Martin <kev82@khn.org.uk> wrote:
>> 1) I'll never be able to remember which modules return tables, and which return a function
> 
> But that's not the kind of thing that'll go unnoticed for very long.

Yes, you're right, not difficult to figure out, but the point is that it's another thing to worry about, which takes my train of thought away from the idea I'm trying to express. This means I'm more likely to screw up what I'm actually doing.

>> 2) I can guarantee that at some point in the future, that module which currently only has one function will need another, and the rewrite will be horrific if not returning a table.
> 
> How so? It seems like a case of just changing:
> 
>    local fn = require "modname"
> 
> to:
> 
>    local t = require "modname"
>    local fn = t.fn
> 

What if you call require from a C module? You'll need to add a lua_getfield()

What if you embed require in statements, such as

load(proxydata.file, "alias file", "t", {
 alias=require("utils").table.keylogger.new(proxydata.tbl)})()

I'm not saying it's impossible, and with a decent refactoring tool, it may be easy, but it just seems to me like a lot of work you can avoid without any major cost (always returning a table) 

I guess it depends how you use require, and how often you use it. Maybe, being the cause of a few design mistakes that have led to major refactoring projects, makes me overly tentative.

Thanks,
Kev