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
From:
Paul LeoNerd Evans
Date:
April 12, 2011 12:13
Subject:
Re: Struct (was: Revising Perl's OO docs - a new OO tutorial)
Message ID:
20110412191315.GB3024@cel.leo
On Thu, Mar 10, 2011 at 11:31:38AM +0100, Johan Vromans wrote:
> Okay, here's my 0.02 cents...
> 
> http://www.squirrel.nl/pub/xfer/Struct.pm

+1

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

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About