lua-users home
lua-l archive

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


On Wed, Jul 22, 2009 at 10:20 PM, Wesley Smith<wesley.hoke@gmail.com> wrote:
>> but OOP has it's place.  in fact, both encapsulation and polymorphism
>> are easy, natural and often helpful in Lua.  inheritance, on the other
>> hand....
>
> Indeed.  I never do anything with inheritance in Lua, but having
> objects is certainly useful to maintain state across a set of
> functions.

Once again the flexibility of the language can bite us.  I've often
wondered if the situation could have been helped if there was a few
'blessed' pure Lua libraries that came with the basic distribution -
currently there's only one, strict.lua!

Two principles about OOP in Lua (a) keep it simple and reusable (b)
pick a scheme, any scheme and stick to it.

Of course, having closures and other means of maintaining state means
that classes only become necessary at a higher level of complexity.

In this discussion (http://lambda-the-ultimate.org/node/3517),
basically a cry for Simplicity, Lua is mentioned but the questioner
also talks about Perl, which encourages the same ad hoc approach:

[[
Curiously enough in the days when I did Perl I found it trivial to
spin endlessly complex datastructures out of arrays and hashes....

...but then found I couldn't maintain them. In ruby I've learned as
soon as I start doing that to make (another) class. Much more
maintainable.
]]

What one can get away with in a script ain't necessarily good for Big
Programs...

The class 'library' I use involves a single function and 'fat
metatable' single inheritance.

http://lua-users.org/wiki/SimpleLuaClasses

steve d.