in reply to To parens or not parens in chained method calls
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.
|
|---|