lua-users home
lua-l archive

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


2017-03-01 3:10 GMT+02:00 Soni L. <fakedme@gmail.com>:

> So, Lua has very limited OOP:
>
> object:method() --> object.method(object)
>
> But, there are other forms of OOP which are useful:
>
> object.system.method(object)
> object.trait.method(object)
>
> These could be added to Lua as a new syntax sugar, the `:.` syntax:
>
> object:system.method()
> object:trait.method()
>
> I believe Lua would benefit from this. Sure, you can just keep a reference
> to the object in object.system/object.trait, but then you can't dynamically
> add new arbitrary systems/traits:
>
> object.trait = sometraitimpl
> object.trait:method() -- wait, why are you not modifying my `object`?
>
> object.system = somesystem
> object.system:method() -- ??? you're supposed to modify `object` D:
>
> object.system.ref = anotherobject -- brokenpatching at its finest
>
> And this is why I think it's a good idea.
>
> This could also support any level of nesting:
>
> a.b.c:d.e.f.g() --> do local c = a.b.c; c.d.e.f.g(c) end -- note how `a.b.c`
> is only evaluated once

Quick standard questionnaire, marks from 0 to 10, 5=neutral,

1. Clarity of proposal?
2. New idea?
3. Do opportunities for using it arise often?
4. Will it improve clarity of coding?
5. Efficiency?
6. Attractiveness of implementation?

My ratings:

10, 0 (the OP himself claimed to have proposed this before April 2016 [1]),
 8, 10, 5, 2 (prefer the way suggested in [2]).

Cloud Wu has pointed out the start of the previous thread; my references
also come from there.

That time, only the three of us endorsed the idea. Maybe its time has
now come.

[1] http://lua-users.org/lists/lua-l/2016-04/msg00186.html
[2] http://lua-users.org/lists/lua-l/2016-04/msg00184.html