On Jul 16, 2004, at 2:01 PM, Dave Rolsky wrote:
Let me cut off this line of discussion, because I really, really, really
hate this style of dual-purpose methods. The reason I dislike it so much
is that it's impossible to distinguish between a mutator and an accessor
that accepts arguments to affect what it returns.
I've been fond of this argument myself, Dave. And I like having separate mutators. But it's extremely common among Perl modules, and really no different than the idea of true attributes. Using lvalue subs, for example, one could:
$d->day; # Accessor $d->day = 1; # Mutator
...and this is how Perl 6 will behave, FWIW. But just by looking at it, you can't tell if an attribute is settable as well as readable. I think it's pretty common to consult the docs for cases such as this.
But if you must have self-documenting methods, then maybe the Java approach will be more meaningful and consistent for people:
$d->get_day; $d->set_day(1);
After all, it's unlikely that anyone would then ever try:
$d->get_day(1);
Regards,
David
smime.p7s
Description: S/MIME cryptographic signature