Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: OO in Perl 6

by revdiablo (Prior)
on Oct 17, 2006 at 17:22 UTC ( #578847=note: print w/ replies, xml ) Need Help??


in reply to OO in Perl 6

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.)


Comment on Re: OO in Perl 6
Select or Download Code
Replies are listed 'Best First'.
Re^2: OO in Perl 6
by chromatic (Archbishop) on Oct 17, 2006 at 17:31 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://578847]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2015-07-29 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls