Because lots of brackets (parens to those of us on this side of the puddle) often make code harder to read even if they make it easier to explain. I would venture a guess that most veteran programmers aren't spending the majority of their time writing code that is meant to be read by novices.

They also make it more difficult to write. Your example, with two sets of parens, requires 8 more keystrokes if you count the shifts. That could add up to 12 inches or more of fingertip movement. When you write a lot of code that can be a very real concern.

I'm not at all suggesting that one should write the leanest code possible, and I want to make that clear. A good rule of thumb is that you should write your code so that someone with skills comparable to your own will be able to easily read it. Consistency in your style will help you achieve that more than anything else. As our style evolves, our code generally becomes less cluttered as a matter of course.

Of the variations below, all of which do the same thing, I prefer the last two.

return ( ( $status == 0 ) ? 0 : 1 ); # Too cluttered. return ( $status == 0 ) ? 0 : 1; # Misleading. return ( $status == 0 ? 0 : 1 ); # Clear return $status == 0 ? 0 : 1; # Clean and clear.
-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Re: variable set to 0 ? 0 : 1 by sauoq
in thread variable set to 0 ? 0 : 1 by c

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.