lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



> From: Andre de Leiradella
> >For static members you can use the setfenv trick.  Here is 
> an example, 
> >but beware I didn't test this as much as I usually do 
> because I have a 
> >unch date that I'm late for.
> 
> Will have a closer look on that...
> 
> >I recomend using parent:doSomething(a, b, c) for explicitly calling 
> >inherited methods.
> 
> You mean parent.doSomething(self, a, b, c)? Two things bother 
> me with this
> aproach: having to name the parent class which make code 
> harder to mantain and having to type self over and over... I 
> could type inherited(self, 'doSomething')(self, a, b, c) to 
> get rid of the explicit class name, but it's terrible to read 
> and makes me write self twice for each inherited method call.

This is something you have to do in Python as well, type the parent
class name. For example, in a Python class that inherits:

class A(B):
	def __init__(self):
		B.__init__(self)

A inherits from B, on a = A(), A must explicitly call B. Its quite clear
how it all works. I maintain a fair amount of Python code and I don't
see it as a problem. It's not a huge overhead to type self. A lot of
people complain when the first start using Python because of the
indentation and self. Its just something you get used to and I think
it's part of what makes the code so readable. Lua is almost worse with
the ":" sugar because automagic variables appear. I know this can be
avoided using:

A = {}
function A.foo(self) ... end
A:foo()

I think the above is more clear - : should just be used for calling, not
in the declaration, i.e.

A = {}
function A:foo() ... end
A:foo()

--Nick