in reply to Re^4: Class attribute get/set approach flaws?
in thread Class attribute get/set approach flaws?
Why, the obvious way... I avoid the necessity, of course!
My accessors take a single optional scalar. Period.† If I have to pass a reference, I do. If I need to clone it, I do. It's easy. Straight forward. Simple. (And I'm really embracing simplicity as much as possible these days.) Mostly, my accessors look something like:
sub foo { $self = shift; @_ <= 1 or croak 'Too many arguments (' . @_ . ')'; if (@_) { # do whatever I need to. } return $self->{foo}; # Or whatever. }
I think the biggest plague among Perl programmers is a drive to be altogether too tricky when there isn't a real good reason to be. I know enough about Perl's quirkier features to believe it's better to avoid most of them much of the time.
I've taken the Ruby-on-Rails slogan, "Convention Over Configuration" and modified it for my personal use:
Convention Over Confusion
† Well, okay... not "period" exactly... There are exceptions to every rule... but relatively few to this one.
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Class attribute get/set approach flaws?
by diotalevi (Canon) on Nov 29, 2005 at 01:37 UTC | |
by sauoq (Abbot) on Nov 29, 2005 at 02:55 UTC | |
by diotalevi (Canon) on Nov 29, 2005 at 03:01 UTC |