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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.