lua-users home
lua-l archive

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

Javier Guerra <> dixit:

> - 'fat metatables': if class B inherits from class A, just copy all
> methods from A to B before defining B's extra and overriding methods.
> after all, you're copying only references, and the copy process will
> be executed only once at startup time.  it's faster since the LuaVM
> will do just a single 'fallback' to a metatable, and also lets you
> pick and mix from different classes; adding mixins and maybe not
> inheriting everything.  in fact, makes inheritance just a shorthand
> for some common cases without forcing you to express everything in a
> hierarchy.

Thank you, Xavier, for this clear explaination. Well, I did fat metatables without knowing the name for that. As you show it, this model allows simple and direct customization without any artificial (& wrong) constraints (I would say: dynamic languages need not Java horrors).

What you say about classes applies at single object level as well, I guess. This is rather my POV and the reason why I chose a prototype-based model.
The main difference with the model you expose, IIUC between lines, is that types/classes are fully functional ordinary objects. While in your case classes rather seem to be only metamethod holders.

I still have a question about metatables, rather about a language design choice. Metamethods are identified through table _key_ names, which builds an indirection (and imo complicates the model). This in particuliar forces metamethod be held in another table, namely the metatable. Why not, like in several other languages, identify metamethods directly by their _own_ name?
The result seems to be that metatables must be copied, if only to allow further customization (in addition to other things to do at type/instance creation time). In the simplest case, when copying an object one must not forget its metatable... I'm surprised about the overhead, too, because people in the Lua community seem (even more) obsessed with machine performance.
Without the indirection introduced by such a model, only generic behaviour methods needs be copied (actually references only, as you say it), not key-pointers to them (in an external metatable).
I guess there is a certain advantage for Lua's model, but I am unable to find it myself (except for not polluting type/object namespace, but in practice this argument does not hold.)


la vita e estrany