develooper Front page | perl.perl5.porters | Postings from April 2011

Re: Struct (was: Revising Perl's OO docs - a new OO tutorial)

Thread Previous | Thread Next
Paul LeoNerd Evans
April 12, 2011 12:13
Re: Struct (was: Revising Perl's OO docs - a new OO tutorial)
Message ID:
On Thu, Mar 10, 2011 at 11:31:38AM +0100, Johan Vromans wrote:
> Okay, here's my 0.02 cents...


I like it. It's small simple useful. Most importantly, its name doesn't
include the word "object" or "class". This immediately jumps out as
being useful in all those little cases where in Perl I get upset about
the lack of C's struct types and begrudgingly use a hash instead,
potential for key typoes and all.

 my $point = { x => 100, y => 200 };
 say "Point is at " . $point->{x};

Or sometimes I 'use constant' up a set of index constants, and use those
instead. They're much less friendly on the eye though.

 use constant { POINT_X => 0, POINT_Y => 1 };

 my $point = [ 100, 200 ];
 say "Point is at " . $point->[POINT_X];

Nowhere in this world does there need to exist any of the machinery of
being an object. OO is a very powerful hammer, but not every "I want a
little tiny composite value type" problem is a nail.

Paul "LeoNerd" Evans
ICQ# 4135350       |  Registered Linux# 179460

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About