
gerti at BITart
Sep 19, 1995, 9:13 PM
Post #3 of 3
(84 views)
Permalink
|
> I have by now implemented a few OO modules in perl. One thing > that strikes me is that I get very tired by typing (and reading) > "$self->" (or "$this->") all the time. Can't we add > some syntactic sugar to make the life of OO programmers easier? I am not sure about this one. Readability of the code is an issue here, and also the problem, that since perl5 almost everything is syntactically legal anyway, and that makes debugging quite a pain... > What I think would be desirable is to have a new keyword that would > replace "sub" for methods. I believe this was discussed on p5p a > year(?) ago but I don't remember much of that discussion. > > In the examples below I have used "method" as the new keyword. > When you declare a sub as method these things could happen: > > The statement "my $self = shift;" is automatically added to the > beginning of the procedure body. Makes sense (other that I personally hate my and prefer local, but that is another story). $self should also be tested on being an object. However, there should be a distinction between class methods and Instance methods (Objective C uses '+' for class methods and '-' for instance methods, where perl uses the sub), and in a class method $self should be tested being a package reference. > Every access to a variable that is not previously declared "my" > or fully qualified is looked up in $self->{}. I.e. $a is > $self->{a} and @a is @{$self->{a}}. Again, this looks like to much magic for me. From my experience, especially in larger OO projects (and OO projects tend to be that way), I usually wished, Perl would rather be on the more restrictive side. With that much 'magic' going on, it is very easy to get hopelessly lost. But what about using a character like '!' for the '$self->{}' part? So, $self->{'foo'} would become $!foo etc. You can call another method for the same object without typing $self. "->foo" is equivalent with "$self->foo;". And, of course, I have to ask for the '$super' again... [munch] > -- > Gisle Aas <aas [at] oslonett> > Oslonett AS > <http://www.oslonett.no/home/aas/ Gerd Knops gerti [at] BITart
|