lua-users home
lua-l archive

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

>On Mon, Jun 16, 2003 at 09:39:48AM -0300, Andre de Leiradella wrote:
>> . explicitly calling inherited methods;
>> . static properties;
>> . static methods.
>What's the problem with using, ...), and
>Classname.baz(...), supposing you implement OO the usual way?
>setmetatable(Foo, {__index=Bar})
>    return setmetatable({}, {__index=Foo})
>and so on.
>I think having to explicitly give the class name is a Good Thing and so
>is having to explicitly refer to objects variables (be it @ or self).
>Although I rather stick to simple languages and haven't used C++ and
>such much, I think implicit OO scope tends to make code hard to read.
>If I had to write C++, I'd be using some clsnm_ prefix for the variables
>to keep things clean.
There is nothing wrong about it besides (in my opinion):

1. It's verbose as you have to repeat and self:xxx and, ...) (you'll probably consider it a bonus);
2. It's easy to make mistakes (forgetting to list self when calling an
inherited method, typing an '.' instead of a ':' etc.);
3. It's harder to maintain (if you change the super class of your class
you'll have to change all ocurrences of the old super class to the new one).

I don't want to start a discussion about this, just want some thoughts from
others who think using @ to access instance members is good.

By the way I'm testing a class preprocessor that already does the following:

. Turns @xxx into
. Turns @xxx(...) into self:xxx(...)
. Turns @@xxx(...) into findInherited(self, 'xxx')(self, ...) (or anything
else, this behavior is user-defined)
. Correctly handles nested inherited calls, i.e. turns @@xxx(@@yyy()) into
findInherited(self, 'xxx')(self, findInherited(self, 'yyy')())

It doesn't handle static properties and methods, so if anyone have ideas on
this I'd like to hear.


Andre de Leiradella