I won't comment on the Perl 6 00, but I couldn't help but notice this comment:
I see [perl5's object system] at as very elegant and minimalist.Perl 5 OO is great, but once I started working with other OO languages, I realized that there are some features that are missing.
I want to be able to do method overloading based on signatures. That's not build into Perl. In Java, it's simple"
public void foo(int x) { // do something with x } public void foo(int x, int y) { // do something with x and y }
In Java, the number of arguments and their types will determine which method is called. In Perl, you generally have to build your own dispatch method (there are CPAN modules to do this) and this is prone to bugs.
I would like a clean separation of class and instance data. In Java, I can simply use the "static" keyword.
Want private variables and methods? Use the "private" keyword. They're not too hard to do in Perl, but that seems like an accident. I frequently use anonymous subs attached to lexical variables to get private methods, but that's not intuitive to a new Perl programmer.
Protected methods in Java can only be used by the class or its subclasses. Trying to prevent a calling program from using them is fairly easy, but it's not built in to Perl.
And the "canonical" example of a Perl constructor:
sub new { my ($class, %data) = @_; bless \%data, $class; }
Now anyone who wants to violate encapsulation can do so by reaching directly into the object. Also, you lose the benefit of using "strict".
This is not to say that Perl's OO is awful. Multiple inheritence can be good (if you really need it -- delegation is typically better), but Java's "interface" hack doesn't allow them to solve their single-inheritance limitation.
Cleanly building a bunch of accessors and mutators on the fly in Perl is a breeze. Not so for Java. You typically have to cut-n-paste the code (if I recall correctly, EJB can solve this problem).
Perl's OO is very easy to use and I quite like it, but it does have some limitations and people should be aware of them.
Cheers,
Ovid
New address of my CGI Course.
In reply to Re: perl6 & OO
by Ovid
in thread perl6 & OO
by chance
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |