Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Your entire post is predicated on a simple straw man argument. You claim that Aristotle is against method chaining because he isn't "used to" it. Frankly, I think that's condescending and silly, but it's also wrong. The argument isn't that it's hard to "get used to," but that even if you are intimately familiar with it, it's hard to understand code that uses it. Take this code example:

$foo->bar(2)->baz(3)->qux;

Versus this one:

my $bar = $foo->bar(2); $bar->baz(3); $bar->qux;

The first requires a lot more effort to decipher than the 2nd. If you're not familiar with the methods and their return values in the 1st snippet, you'd have to look them up in the documentation. Even if you knew the method return values off the top of your head, you'd have to trace the chain carefully to make sure you understand what's going on.

In the 2nd, if you didn't know the return values, you could take a reasonable guess, and probably be right. And if you did know the return values, then it's obvious what's going on without any thought required at all. This is called self documenting code, and it's generally something we strive for.


In reply to Re^4: Mutator chaining considered harmful by revdiablo
in thread Mutator chaining considered harmful by Aristotle

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 having a coffee break in the Monastery: (4)
As of 2024-03-29 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found