Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Transaction time for LWP::UserAgent GET

by William G. Davis (Friar)
on Jul 24, 2003 at 07:59 UTC ( [id://277467]=note: print w/replies, xml ) Need Help??


in reply to Re: Transaction time for LWP::UserAgent GET
in thread Transaction time for LWP::UserAgent GET

First, "indirect object" syntax for method calls is best avoided.

Really? If you're not doing anything too complicated, then what's wrong with the indirect object syntax, and why should it be avoided? It works, and personally, I think it looks much, much better. When used for constructors, the syntax almost reads like English:

my $ua = new LWP::UserAgent;

"Create a new LWP User Agent."

Replies are listed 'Best First'.
Re: Re: Re: Transaction time for LWP::UserAgent GET
by sauoq (Abbot) on Jul 24, 2003 at 19:08 UTC
    If you're not doing anything to [sic] complicated, then what's wrong with the indirect object syntax, and why should it be avoided?

    The biggest problem with indirect object notation is that perl has to jump through hoops to decide whether method Class; should be interpreted as Class->method() or method("Class") and small changes to the order of those hoops can make perl change its mind. That can result in the appearance of nasty hard-to-find bugs in previously working code after a small seemingly innocuous change.

    When used in instance method calls, the "object" suffers from the same brittle parsing that the filehandle argument to print() does. That is, however, a relatively uncommon practice in comparison to the habit of using it for class methods, particularly constructors.

    You are right that problems rarely arise in simple use. But, they do exist whether or not you are doing something complicated. That means you could be bitten when your simple code goes through several iterations and becomes more complicated or if you continue to use the syntax out of habit even when you take on a more complex project.

    Look at it this way... If you get tripped up by a subtle bug caused by the finickiness of indirect object syntax, you'll likely spend an hour or more pulling out your hair trying to debug a problem that you are sure you shouldn't be seeing... And when it's all over and you've determined the cause, you'll swear an oath never to use indirect object notation again anyway.

    Or, you might never run into the problem in which case you'll keep your hair as well as the bad habit and eventually you'll be hired as a PHB and stop coding altogether. But then you'll be forever furtively glancing over your shoulder in fear of the inevitable attack by a bald maintenance programmer with a strong homicidal urge brought on by debugging your code...

    Why not save yourself the trouble by breaking the bad habit now? ;-)

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found