in reply to Re: Re: chaining method calls
in thread chaining method calls
My opinion is that cascading is an idiom that doesn't translate well into Perl. Without a special syntax to designate a cascade, a simulated cascade is indistinguishable from a gross violation of the Law of Demeter.
That's an interesting point, and the most convincing one I've come across against the idiom. I can see how a maintainence coder might see a cascade and have it look like a ghastly exposure of internals ripe for refactoring.
That said, it's not a problem I've ever come across. Probably because that by the time you're looking at the code you already have an idea of what methods are associated with what objects, so you can mentally parse out cascades from other code.
The fact that I try not to write objects that flagrently violate the LoD probably helps too :-)
(I wonder if Perl6 will have an explicit syntax? If not we could always make one up.)
I still find:
$my_object_variable->foo($x)->bar($y)->ni($z);
clear, and preferable to:
$my_object_variable->foo($x) $my_object_variable->bar($y) $my_object_variable->ni($z) # or for ($my_object_variable) { $_->foo($x); $_->bar($y); $_->ni($z); };
To me the former is succinct and obscures the mainline less. Probably too much Smalltalk at an early age :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^3: chaining method calls
by perrin (Chancellor) on Jun 12, 2003 at 20:24 UTC | |
by Ovid (Cardinal) on Jun 12, 2003 at 21:06 UTC | |
by dws (Chancellor) on Jun 12, 2003 at 21:12 UTC | |
|
Re: Re^3: chaining method calls
by BUU (Prior) on Jun 12, 2003 at 17:38 UTC |