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:
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
|
|