in reply to Re^6: Method Chaining and Accessors
in thread Method Chaining and Accessors
... At this point i'm not sure if i'm repeating myself or not ...
q{ You have an odd notion of what's "clean" }. This is true, I learnt perl by reading merlyn's (et al) llama and TheDamian's Perl Best Practices, so I suspect that my view may be a little tainted by what I've been told is "just the right way to do it".
Yes, you do get stuff from the SYNOPSIS the first time, but after that, you should be able to guess the interface of the module, getters, setters and all should become fairlly obvious to guess after a short period of use.
q{ Well, different things should look different, right? }. Yes this is true, a constructor should look like one, and a setter method should look like one. Things should look different, but if something is wrong, it should always look wrong.
I suppose that i've just somewhat countered my own point, but get_* and set_* will always look right on instances of my class, and always look wrong on instances of yours (as long as the instances are named uniformly - ie you don't call an instance of Doom something like $f00li5h)$f00li5h = f00li5h->new(); $f00li5h->{moose}; # looks wrong because my objects never work +that way $f00li5h->get_moose; # *magic* $f00li5h->set_moose( 8 ); # *magic* $doom = Doom->new(); $doom->get_moose; # looks wrong - your objects don't work like + that $doom->{moose} # wrong-o $doom->moose; # *joy* this is the ticket $doom->set_moose( 21 ); # looks right to people who often use doom's + objects
I'd say that their looking similar makes for a uniform interface... also:
don't look too similar due to the argument to set_*$f00li5h->get_foo; $f00li5h->set_foo('new value');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Method Chaining and Accessors
by doom (Deacon) on Apr 13, 2007 at 19:23 UTC | |
by chromatic (Archbishop) on Apr 14, 2007 at 07:38 UTC | |
by doom (Deacon) on Apr 14, 2007 at 08:08 UTC | |
by f00li5h (Chaplain) on Apr 14, 2007 at 03:31 UTC |