lua-users home
lua-l archive

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

On Friday 21 November 2008, Michal Cizmazia wrote:
> -- What do you think about the following object-oriented approach,
> -- in which a function is used to create an object using closures?
> -- I am looking forward to your responses.
> -- Michal Cizmazia

as i see it, compared with the more common metatable methods:

 - you can pass 'methods' as parameters to other (non-aware) functions.

 - higher memory  footprint, increases with number of object instances
 - slower object instantiation
 - uses '.' instead of ':' (others will see this one as a pro, it's a matter 
of taste)

both Python and JavaScript do something similar to this, precisely because 
it's the only way to get a method as a function (closure) value.  In both 
cases they do it lazily, transforming the 'method' in the 'class' (or 
prototype) into a closure when needed.

I believe (without real proof) that it's a non-trivial contributor to these 
languages (current) slowness and complexity of an optimising JIT.

IMHO, this is one of the biggest strengths of Lua: not having a 'set in stone' 
OOP mechanism lets the users (us) choose the best model for each situation 
without having to carry the overhead when you don't need it.  that also means 
that you're free to use this method if you like it better without any 
negative impact to other users.  interestingly, Lua's well-designed set of 
primitives even makes it easy to interoperate between different OOP methods 
(at least if you don't need to inherit between 'families')


Attachment: signature.asc
Description: This is a digitally signed message part.