[Chicago-talk] Class::Accessor uses a hashref - a question ofstyle

Jay Strauss me at heyjay.com
Sun Jan 25 17:48:45 CST 2004

Sure, I don't mean to say that I always use hashes (although I do like them,
because they are sorta self documenting), obviously if something only takes
a single arg I'd use a scalar, but when some parms are optional, a hash is

But my question was really: When using hashes for my parameter list is it
better to use a hash or hashref

----- Original Message -----
From: "Steven Lembark" <lembark at wrkhors.com>
To: "Chicago.pm chatter" <chicago-talk at mail.pm.org>
Sent: Sunday, January 25, 2004 5:49 PM
Subject: Re: [Chicago-talk] Class::Accessor uses a hashref - a question

> > Now the question:  Is it just a personal preference to use a hash or a
> > hashref when creating a class.  Or is one one syntax preferred by those
> > people who make the rules?
> Hash ref's are common because people are used to C
> structs for thier objects. The $obj->{name} syntax
> is reasonably flexable and more descriptive than,
> say, arrays with positional access in most cases.
> So... people use hashes.
> For lazy instantiation scalars are often simpler;
> Tim Bunce chose to use an empty anon hash for its
> unique conversion to text; he could just as well
> have used a scalar in most cases. For queues it
> is often easier to use an array, since you can just
> shift @$obj; iterators are more easily done with
> closures (i.e., sub referent) that process the
> iteration.
> Net result is that there are situations where
> hashes are not all that convienent (especially
> queues). It's probably a good idea to think hard
> about what you are going to do with the object and
> how it will be used before blindly implementing it
> as a hash every time [hey: designing before you
> implement, maybe I could get a patent... :-].
> --
> Steven Lembark                               2930 W. Palmer
> Workhorse Computing                       Chicago, IL 60647
>                                             +1 888 359 3508
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk

More information about the Chicago-talk mailing list