lua-users home
lua-l archive

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

On Mar 5, 2017, at 2:58 PM, Petri Häkkinen <> wrote:

> On Mar 5, 2017, at 1:32 PM, Dirk Laurie <> wrote:
>> Without colon notation, how far can we get?
> If there we no implicit self and no ':' sugar this would be written something like this:
> local file ="results.txt", "w")
> io.write(file, table.concat(results, "\n"))
> io.close(file)

And to extend on my reply a little bit…  I don't think the difference between these two versions matter at all. Most of the CPU time is spent in file i/o and table.concat anyway (in the other thread I gave some examples where the speed difference can matter).

The original question was about object composition and extending the ':' notation and I was trying to say that it's actually valid to separate code and data (I.e. not  use OOP) and just use free functions to do your thing. I.e. instead of doing object.system:do_a_thing() or whatever just call object_system_do_a_thing() and pass whatever data you need in. You can still think of your data as objects, it's just the code that is written in imperative style. Simple.

The other ramblings I had were just about giving some ideas to people who may be too accustomed to think in only classes & object (I used to be one).

Hopefully I'm not sounding arrogant or besserwisser or anything like that. Just trying to be helpful.