middleclass & extras: middleclass 3.0 is out!

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: middleclass & extras: middleclass 3.0 is out!

Post by kikito » Sun Jul 27, 2014 11:07 am

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.
When I write def I mean function.

User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

Re: middleclass & extras: middleclass 3.0 is out!

Post by murks » Tue Jul 29, 2014 11:33 am

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.

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: middleclass & extras: middleclass 3.0 is out!

Post by bartbes » Tue Jul 29, 2014 1:01 pm

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?

User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

Re: middleclass & extras: middleclass 3.0 is out!

Post by murks » Tue Jul 29, 2014 5:24 pm

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.

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: middleclass & extras: middleclass 3.0 is out!

Post by bartbes » Tue Jul 29, 2014 9:00 pm

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.

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: middleclass & extras: middleclass 3.0 is out!

Post by kikito » Tue Jul 29, 2014 9:26 pm

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.
When I write def I mean function.

User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

Re: middleclass & extras: middleclass 3.0 is out!

Post by murks » Thu Jul 31, 2014 9:27 pm

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.

User avatar
Roland_Yonaba
Inner party member
Posts: 1562
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: middleclass & extras: middleclass 3.0 is out!

Post by Roland_Yonaba » Thu Jul 31, 2014 9:59 pm

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.

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: middleclass & extras: middleclass 3.0 is out!

Post by bartbes » Fri Aug 01, 2014 10:20 am

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".

User avatar
murks
Party member
Posts: 185
Joined: Tue Jun 03, 2014 4:18 pm

Re: middleclass & extras: middleclass 3.0 is out!

Post by murks » Fri Aug 01, 2014 11:23 am

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests