Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I agree that the dot syntax is a bit easier to type, and I think overall the syntactic change is worth the (very small, for me anyway) pain it takes to re-learn. A more significant change, in my mind, is how most object code will actually be written. It won't take nearly as much code to accomplish the same goals. Consider an example:

class Point { has $.x; has $.y; method str { return $.x ~ "x" ~ $.y; } } my $point = Point.new(x => 2, y => 3); say $point.str;

Compared to the equivalent Perl 5:

{ package Point; sub new { my $name = shift; my %attr = @_; return bless { %attr }, $name; } sub x { my $self = shift; return $self->{x}; } sub y { my $self = shift; return $self->{y}; } sub str { my $self = shift; return $self->x . "x" . $self->y; } } my $point = Point->new(x => 2, y => 3); print $point->str, "\n";

I think you'll agree that the Perl 6 version makes it a lot easier to get on to the heart of the matter. I really like it.

(Of course, we can get most of the same conciseness in Perl 5 with Moose, which I am very excited about. But that came as a result of the Perl 6 OO design, so credit where credit is due.)


In reply to Re: OO in Perl 6 by revdiablo
in thread OO in Perl 6 by Scott7477

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2021-09-26 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?