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 & middleclass-extras: OOP for LUA

Post by kikito »

Just a clarification: I'm not ignoring thelinx. On the contrary: I'm very grateful for him to having taken the time to send a patch. He's the man.

It's just been a very busy week and I haven't had time to do much Lua. And I'm not sure I will be able to program this weekend, neither.

Thelinx's change request changes the init.lua files so they it is more or less 'impervious' to middleclass(-extras) being put inside a folder (/lib/middleclass instead of just /middleclass/).

My initial impression was that the 'standard' way of dealing with this was modifying package.path (on the example before, package.path = '/lib/?;' .. package.path).

I'm not really sure about what option do I like the most:

Code: Select all

 -- Current solution (while we are at it, we could also include init.lua in the loading)
package.path = '/lib/?;/lib/?/init.lua' .. package.path 
...
require('middleclass')

-- thelinx's solution
require('lib.middleclass.init')

I'm split about this. thelinx's solution is simple. Current solution is more 'semantic' ... but then, middleclass 's supposed to make common things easy to do...

So I'll probably end up accepting thelinx's solution. I'm taking my time because I want to do tests before including them. More precisely, I want to test that everything works ok happens if package.path is modified, and if middleclass is transformed into a luarock.

In the meantime, if anyone else has any opinion in the whole package.path-modified-vs-including-lib-easily, I'd be glad to hear it.
When I write def I mean function.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: middleclass & middleclass-extras: OOP for LUA

Post by thelinx »

uh

my change only makes it so even if you require("lib.middleclass.init") instead of require("middleclass.init"), it wont error.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: middleclass & middleclass-extras: OOP for LUA

Post by kikito »

I know but, will it work if someone has modified package.path so instead of requiring lib.middleclass.init they just require middleclass.init? or lib.middleclass ? I have to test those things too.
When I write def I mean function.
User avatar
ZenX2
Citizen
Posts: 89
Joined: Wed Nov 17, 2010 5:35 am

Re: middleclass & middleclass-extras: OOP for LUA

Post by ZenX2 »

I made a small rewrite of this, with a few features like being able to use class.name() instead of class("name"), and using :__init for a function called on initialization (the __ is because it seems internal, ya know?)
If it's alright, I can upload it.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: middleclass & middleclass-extras: OOP for LUA

Post by kikito »

ZenX2 wrote: ... use class.name() instead of class("name")
... use __init for a function called on initialization (the __ is because it seems internal, ya know?) ...
I don't see the advantage of using class.name() instead of class("name"). It's only 1 character less, and would make implementing class less straightforward.

Regarding __init, well that is really a matter of taste. Python calls constructors __init__. Ruby calls them initialize. Since I like ruby more, I choose initialize. (btw, you may want to rename 'destroy' to something more pythonesque too, like __del).

So I won't include any of those two changes on my branch. But I encourage you to create a fork! Someone might be interested in your changes.
When I write def I mean function.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: middleclass & middleclass-extras: OOP for LUA

Post by nevon »

I would very much welcome a more Python-esque fork, as long as it was kept up to date with "mainline" Middleclass.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: middleclass & middleclass-extras: OOP for LUA

Post by zac352 »

kikito wrote:Regarding __init, well that is really a matter of taste. Python calls constructors __init__. Ruby calls them initialize. Since I like ruby more, I choose initialize.
Initialise. I speak British English. :P
Hello, I am not dead.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: middleclass & middleclass-extras: OOP for LUA

Post by kikito »

zac352 wrote:Initialise. I speak British English. :P
Well, I learned US English when I grew up, so for me it's initialize, color, and truck. Interestingly enough, I say 'lift' instead of 'elevator'. I guess I like shorter words.

Besides that, I'm copying ruby, which was created by this Japanese guy. I guess they use US English in Japan too.
When I write def I mean function.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: middleclass & middleclass-extras: OOP for LUA

Post by tentus »

A lot of the US spellings are older (though it's a mixed bag), so it makes sense for a third party to use the more common and more historical spelling. A lot of the US versions are also shorter and easier to remember if you don't natively speak English (armor as opposed to armour).

To be fair to my island cousins, I find a lot of the British spellings more visually appealing and easier reading in prose or poetry, but in coding it just makes more sense to use the US versions. Whichever you go with though, be sure to be consistent- nothings more irritating than having to make a list of notes as to which spelling the authors used for which words.

Disclaimer: I speak Appalachian English, which has a whole host of unusual spellings and pronunciations used locally. Yonder is a common word in my day to day speech. Most of my kin, myself included, make a point of using standard US English when on the internet.
Kurosuke needs beta testers
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: middleclass & middleclass-extras: OOP for LUA

Post by zac352 »

tentus wrote:Whichever you go with though, be sure to be consistent- nothings more irritating than having to make a list of notes as to which spelling the authors used for which words.
I'm consistent. :P
Hello, I am not dead.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests