[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Colon notation in object-oriented programming
- From: "Soni L." <fakedme@...>
- Date: Sun, 5 Mar 2017 11:26:20 -0300
On 05/03/17 10:25 AM, Petri Häkkinen wrote:
On Mar 5, 2017, at 2:58 PM, Petri Häkkinen <firstname.lastname@example.org> wrote:
On Mar 5, 2017, at 1:32 PM, Dirk Laurie <email@example.com> 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 = io.open("results.txt", "w")
io.write(file, table.concat(results, "\n"))
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.
Here's a challenge for you:
Write an extensible game modding API, using only static non-replaceable
functions, and without ever deferring to an object function inside them.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.