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

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