Hash or List to constructors

David Dick david_dick at mbox.com.au
Sun Jun 30 18:30:15 CDT 2002

what i usually use is a hash ref, based on a couple of things.

First, that way, everyone using the framework understands that you
always pass a hash ref to the constructor.

Second, the hash can handle infinite changes to it's composition, which
is useful in prototyping and subclassing.

Thirdly, most of my work tends to involve the high probability of
passing massive parameters (bloody html :)) in the arguments and it is
probably best for saving space to only pass a reference instead of the
full hash.


----- Original Message -----
From: Scott Penrose <scottp at dd.com.au>
Date: Monday, July 1, 2002 8:59 am
Subject: Hash or List to constructors

> Hi Dudes,
> I was wondering people opinion on constructors.
> I have a new module I am writing which currently requires two 
> inputs 
> (device, strobe). The first being a scalar and the second a number. 
> I 
> thought also that I may in the future have an optional 3rd 
> parameter 
> which is the timeout between the strobe.
> I am wondering if it is better to go for a hash
>    ->new(device => 'somedevice', strobe => 15, interval => 150, ...)
> of is it better to extend the list of values?
> My preference for simple constructors (eg: DBI) is to hand just one 
> parameter. But for complex entries (eg: DBI options) it is best to 
> use a 
> hash, or even a hash ref.
> Preferences, feedback ?
> Scott
> --
> Scott Penrose
> Welcome to the Digital Dimension
> http://www.dd.com.au/
> scottp at dd.com.au
> Dismaimer: Contents of this mail and signature are bound to change 
> randomly. Whilst every attempt has been made to control said 
> randomness, 
> the author wishes to remain blameless for the number of eggs that 
> damn 
> chicken laid. Oh and I don't want to hear about butterflies either.

Would you like to receive faxes to your personal email address?
You can with mBox.  Visit http://www.mbox.com.au/fax

More information about the Melbourne-pm mailing list