Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm definitely not a fan of this call-style. My prefered syntax for accessor/mutators is to have a single method which sets the value if passed a parameter and always returns the current value. This yields calls that read easily and behave in a consistent manner. If $train->speed returns the speed of the train why would $train->speed(10) return the train? It only makes sense if you're already familar with the syntax hack it supports, which isn't even in common usage! Hello maintainance nightmare.

I find the argument (put forth by others) that returning an object on success or undef on failure aids debugging to be totally bogus. Let's take your example:

print SOAP::Lite -> uri('http://www.soaplite.com/Temperatures') -> proxy('http://services.soaplite.com/temper.cgi') -> f2c(32) -> result;

What happens if f2c() fails? Fatal error with a strange error message. What happens if result() fails? Nothing! Maybe you get a warning, but you certainly don't get an error. It's much, much better if mutators croak() if they can't perform their duty. Then error checking is entirely optional, yet still available via eval{}.

-sam

PS: All that said, I'm still a big fan of SOAP::Lite. It's got its quirks, but it gets the job done. To all the SOAP::Lite haters in the audience (and I know you're out there) I'm eagerly awaiting your complete SOAP implementations!


In reply to Re: chaining method calls by samtregar
in thread chaining method calls by perrin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found