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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.";

In reply to Re: Re: Re: Transaction time for LWP::UserAgent GET by sauoq
in thread Transaction time for LWP::UserAgent GET by c

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 romping around the Monastery: (8)
As of 2024-04-24 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found