![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^4: Mutator chaining considered harmfulby Anonymous Monk |
on Dec 29, 2004 at 14:19 UTC ( #417986=note: print w/replies, xml ) | Need Help?? |
Mostly it makes it difficult to catch errors if those methods fail. But not any more difficult that catching an error in *any* chaining call. The OP had no problem with:but if there's an error in the child method, it'll be as hard to catch as in:
And if your methods just throw exceptions on errors, you can just wrap it all in an eval: If that isn't good enough for you, because you need fine grained control on catching errors, you can always write: The point is that mutators returning $self allow for either style. Chaining for those who want it, and fine control for those who want that. Returning the argument passed in is IMO not very useful. The OP mentioned "that's how = does it - it allows you to write $foo = $bar = $baz;. That's true, but the OO equivalent would be: which, IMO, gets unwieldy very quickly and isn't very readable either. I also have seldomly any use for that.
In Section
Meditations
|
|