Thanks for all the great feedback!

Since I already omit parens everywhere else I can, for example(s):

print "blah\n"; length ...; push @a, ...; my $obj = Package->new;

...I am going to do the same thing with method calls. I forgot about breaking the chain across multiple lines, but I often do that as well (however without omitting parens):

my @files = File::Find::Rule->file() ->name(...) ->in(...);

So in the end, I'm going to keep with my previous way of omitting parens, and apply that to chained calls. For long chains, I'll break it into separate lines. For short call chains, eg $obj->db->fetch(...);, I'll keep it on one line unless for some reason more clarity is needed in specific cases, then I'll break that up too.

update: Your Mother, I don't do much JS at all, but I have done some, and just had a look at a piece of some of my code:

$(this).children('ul').stop(true, false, true).slideToggle(300);

Looking at your example, it is much, much clearer as to what's happening when the chain is broken across lines. From now on when I have to write JS, I'll be applying your principle.


In reply to Re: To parens or not parens in chained method calls by stevieb
in thread To parens or not parens in chained method calls by stevieb

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.