Page 24 of 25

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Sun Jul 27, 2014 11:07 am
by kikito
Yes, it's a "hook". It's there so that you can (for example) print something on a console every time a subclass of certain class is created.

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Tue Jul 29, 2014 11:33 am
by murks
Thanks kikito. I read that you like monkey-patching, but isn't writing functions just so they can be overwritten a bit extreme? If I wanted that functinality I could just as well modify middleclass with the same result.

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Tue Jul 29, 2014 1:01 pm
by bartbes
He could ship an empty file and you can write your own classes ;).
Considering he wants this hook to exist "officially", he wrote it. It's not weird to have empty functions if they're hooks, they're just placeholders, but that doesn't mean they aren't useful. Yes, in this case instead of adding an empty function, he could've tested if it exists at the callsite, but does that really make anything better?

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Tue Jul 29, 2014 5:24 pm
by murks
But then he should also have called it 0log :P
I guess I'm just a bit irritated because I don't usually write code that does nothing.
I guess he needed that hook at some point and left in in there in case others need it too.

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Tue Jul 29, 2014 9:00 pm
by bartbes
I'm not sure he needed it, it's just a feature that's in there. I'm fairly sure his aim is a complete solution, not a partial diy one.

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Tue Jul 29, 2014 9:26 pm
by kikito
Let me try to explain this.

Object-orientation is not a fixed thing; it's a spectrum.

In Lua, the lower-end of the spectrum (for me) is a simple __index - based thing, as shown in PiL. The highest-end of the spectrum is ... unknown; I guess it could be some complicated castle mimicking Haskell's type system.

When I started programming this library I wanted something that I could use on videogames, so it had to be reasonably fast (more or less on-par with __index-based implementations). I also wanted something small, but bigger than __index. I had to decide how "high" on the spectrum to go.

One Object model that I know reasonably well is Ruby's Object model. While simpler than Haskell's, it still was too much for videogames: it would require a lot of code, and the resulting thing would be slower than the __index-based approach.

That's what drove me to write middleclass: it is a "middle point" between "plain __index" and "the Ruby Object model", with the following requisites:
  • A small number of lines (keeping it 100-ish, without comments)
  • No sacrificing speed (compared to plain __index)
  • Must "feel like Lua", not like another language
This meant that I had to cut down a lot of things. In particular, middleclass' classes are not instances of a Class class, and mixins are not instances of a Module class; the wiring required for that to work made the code too big. Some features were just too expensive time-wise (there was a super keyword in earlier versions of middleclass, as well as built-in support for __index metamethods). But features that I didn't particularly use, but matched the criteria above, where included.

That is why middleclass has an included callback on mixins and a subclassed callback in classes. It's done on Ruby, and it satisfies the requisites, so it is included in middleclass. I remember using subclassed only once when programming one library, but I finally ended up using included instead. I still think it can be useful for debugging purposes, for example.

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Thu Jul 31, 2014 9:27 pm
by murks
Thanks for the explanation kikito.
There is one more odd thing in there, and I saw the same thing in the hump documentation. Maybe it's just a terminology-thing. My background is mostly java, I don't have a ton of experience in other languages.
kikito wrote: This meant that I had to cut down a lot of things. In particular, middleclass' classes are not instances of a Class class, and mixins are not instances of a Module class; the wiring required for that to work made the code too big. Some features were just too expensive time-wise (there was a super keyword in earlier versions of middleclass, as well as built-in support for __index metamethods). But features that I didn't particularly use, but matched the criteria above, where included.
I guess by "middleclass' classes are not instances of a Class class" you mean "middleclass' objects are not instances of a class Class"? I have no idea why any class should be an instance of another class.
I understand the part about mixins even less.

The hump documentation also contains completely confusing statements like:"function class.init(object, ...)
Calls class constructor of a class on an object."

Another question: Is there any reason why middleclass does not implement class commons? Can class commons be used directly? I'm still somewhat confused by the multitude of OOP aproaches in Lua.

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Thu Jul 31, 2014 9:59 pm
by Roland_Yonaba
murks wrote:Another question: Is there any reason why middleclass does not implement class commons?
It does.
Though I am not sure it was updated for MiddleClass 3.0.

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Fri Aug 01, 2014 10:20 am
by bartbes
Roland_Yonaba wrote: Though I am not sure it was updated for MiddleClass 3.0.
It seems like it was.
murks wrote: I guess by "middleclass' classes are not instances of a Class class" you mean "middleclass' objects are not instances of a class Class"? I have no idea why any class should be an instance of another class.
I believe he means "subclass", instead of "instance".

Re: middleclass & extras: middleclass 3.0 is out!

Posted: Fri Aug 01, 2014 11:23 am
by murks
Thanks Roland_Yonaba, I did not know middleclass-commons and I somehow was blind and did not see MiddleClass on the class commons page.

Thanks bartbes, with subclass it makes a lot more sense.