Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Re^3: chaining method calls

by Ovid (Cardinal)
on Jun 12, 2003 at 21:06 UTC ( #265499=note: print w/ replies, xml ) Need Help??


in reply to Re: Re^3: chaining method calls
in thread chaining method calls

The way I see this idiom used is fairly consistent. $self is only returned for mutators (upon success). Thus, the expectations are clear: mutators always return $self upon success and accessors never return $self. If accessors return an object, it's known the the object is not the calling object. That, actually, is yet another reason why I prefer to have separate accessors and mutators ('name' or 'get_name' vs. 'set_name'). This clear distinction makes the expectations clear. And again, if you don't like the chained features, you don't have to use it. Chained method calls are usually an extra feature as opposed to the replacement of a feature that is already used.

I also note that you object to this idiom because it's not common. If it were a bad idiom, I would consider this to be a benefit. If it's a good idiom, then that's a negative. Which way it falls is still kind of up in the air, though. I'm glad you raised the issue.

Cheers,
Ovid

New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)


Comment on Re: Re: Re^3: chaining method calls
Re: Re: Re: Re^3: chaining method calls
by dws (Chancellor) on Jun 12, 2003 at 21:12 UTC
    The way I see this idiom used is fairly consistent. $self is only returned for mutators (upon success). Thus, the expectations are clear: mutators always return $self upon success and accessors never return $self.

    Consistent or not, because there's no first-class support for cascading in Perl, the reader is forced to do a lot of digging to distinguish a simulated cascade from sloppy coupling. Basically, to be sure, you have have to read all of the methods. In a first-class cascade (like those supported by Smalltalk) a surface read is sufficient.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://265499]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-10-22 12:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (117 votes), past polls