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

Steven Lembark lembark at wrkhors.com
Sun Jan 25 17:49:31 CST 2004

> 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

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

More information about the Chicago-talk mailing list