and then use the resulting object, I can still autovivify member variables, leading to a whole raft of typo problems:package hashobject; sub new { my ($class) = @_; $class = ref($class) || $class; my $self = {}; $self->{variable} = 'foo'; return(bless($self, $class)); }
If we move to a pseudohash, the object looks like this:my $obj = new hashobject; $obj->{variablee} = 'bar'; # TYPO... print $obj->{variable}; # Prints 'foo'
And then (mis)use the object in the same way:package pseudohashobject; use fields qw(variable); sub new { my ($class) = @_; $class = ref($class) || $class; my $self = bless([\%FIELDS], $class]); $self->{variable} = 'foo'; return($self); }
the typo actually causes a runtime exception! This makes very hard to find bugs easy to find, and hence is a good thing (tm). I would suggest looking into Damien Conway's Object Oriented Perl (Manning) for more information. I would almost rate this book as more important than the Camel!my $obj = new pseudohashobject; $obj->{variablee} = 'bar'; # TYPO print $obj->{variable};
In reply to RE: RE: My views on pseudohashes
by panache
in thread My views on pseudohashes
by vroom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |