lua-users home
lua-l archive

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


On Mon, Apr 14, 2014 at 5:03 AM, Enrique Garcia Cota <kikito@gmail.com> wrote:
Hi there,

I've written a series of articles about building Lua modules - it's here:


I would appreciate any feedback or comments on it.

Thanks and best regards,

Enrique ( kikito / @otikik )

My thoughts, mostly nitpicks:

> Penlight is a clear example of a function that doesn’t follow this rule. It is a big library that does many different things.

I don't think Penlight is a function.

> Names with more than 1 word are neither under_scored nor CamelCased (for example, getmetatable).

This has been the subject of holy wars since programming languages were invented. I personally prefer camelCase, but I also have a bad habit of not being consistent about it.

> I also recommend adding _VERSION, _DESCRIPTION, _LICENSE & _URL fields to all modules

This is another one of those things which I think doesn't have a real standard. My personal favourite method is something like:
mymodule._info = {
    name = "MyModule",
    description = "Does a thing with the stuff",
    homepage = "http://example.com/MyModule",
    authors = {
        "Rena <hyperhacker@gmail.com>",
        "Tom <tom@example.net>",
        "Dick <chunkylover52@aol.com",
        "Harry <webmaster@bees.net>",
    },
    copyright = "2014 Rena Kunisaki",
    license = "MIT <http://opensource.org/licenses/MIT>",
    version = "1.2.3.4",
}
but there's definitely merit to using just mymodule._VERSION and the like as well.

> While it (very marginally, in most cases) faster

(under "Beware of locals") I think you accidentally a word.

> It’s like trying to make a bike slightly faster by painting it with lighter paint.

I like this, might have to steal it. ;-)

> State is a general programming term that can be think intuitively as internal memory.

Another sentence that could use some grammar touchup. (think -> thought of?)

> Instances leave in the aplication’s memory

Should be "live in" and "application's". "derivate" shortly after should be "derivative".

> This is partly due to some design decisions in the Lua.

Which Lua?

> We can, however, use something: the _expression_ (...), when evaluated at the top of a module, returns the “path” used to require it.

Interesting. I've never seen this. Is it documented somewhere?

> Please enable _javascript_ to view the comments powered by Disqus. comments powered by Disqus

Booooo. Remember when HTML, without scripts, was able to display text and even input fields, all on its own?

--
Sent from my Game Boy.