Page 13 of 25

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Fri Nov 26, 2010 6:00 pm
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.

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Fri Nov 26, 2010 6:09 pm
by thelinx
uh

my change only makes it so even if you require("lib.middleclass.init") instead of require("middleclass.init"), it wont error.

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Fri Nov 26, 2010 10:54 pm
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.

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Sun Nov 28, 2010 6:47 pm
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.

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Sun Nov 28, 2010 7:28 pm
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.

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Sun Nov 28, 2010 8:11 pm
by nevon
I would very much welcome a more Python-esque fork, as long as it was kept up to date with "mainline" Middleclass.

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Sun Nov 28, 2010 11:21 pm
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

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Mon Nov 29, 2010 8:46 am
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.

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Mon Nov 29, 2010 5:46 pm
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.

Re: middleclass & middleclass-extras: OOP for LUA

Posted: Mon Nov 29, 2010 9:16 pm
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