Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Mutator chaining considered harmful

by Aristotle (Chancellor)
on Jan 01, 2005 at 19:00 UTC ( #418675=note: print w/replies, xml ) Need Help??


in reply to Re: Mutator chaining considered harmful
in thread Mutator chaining considered harmful

Yes, I suggested that class authors not return $self from mutators. Of course, as the discussion in multiple method calls against the same object, revisited shows, there are ways to retrofit chaining from the user's end to classes that don't implement it (I was almost going to upload one of those to CPAN).

So I don't see a valid case for returning $self as an enabler of choice: the choice is always available, regardless of the classes interface. What's left then is the question of encouraged usage style (see the docs to SOAP::Lite). And to me, there's no question that this style should not be encouraged, just as there's no question that use of goto should not be encouraged, regardless of one or the other is sometimes the right tool or not (for which there is clear evidence in case of goto; with mutator chaining I've yet to see any).

The only reason to favour chainable mutators I've seen anyone mention is brevity, conciseness. But as a class author you can offer that to users without conflating semantics by offering a single unified setter.

Makeshifts last the longest.

  • Comment on Re^2: Mutator chaining considered harmful

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://418675]
help
Chatterbox?
[stevieb]: I went on my merry way writing a cross-platform, network-aware system that works across Perlbrew and Berrybrew systems and runs unit tests for Perl dists on all installed versions, with the ability to manage *brew commands themselves
[stevieb]: That worked out exceptionally well, as when I started that project, I hadn't delved into hardware development yet.
[stevieb]: found a issue in MetaCPAN::Client though today for my revdep tests. At least I think it's an issue
[stevieb]: I'm working on hiding the fact the software needs MetaCPAN::Client, as I often have a hell of a time installing it. I'm going to change it to let the user know if they do revdep that it needs to be installed, and remove that distribution ..
[stevieb]: ...from being a prereq

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2017-06-25 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (572 votes). Check out past polls.