in reply to Re: variable set to 0 ? 0 : 1
in thread variable set to 0 ? 0 : 1
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.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re(3): variable set to 0 ? 0 : 1
by talexb (Chancellor) on Sep 07, 2002 at 04:33 UTC | |
by Flexx (Pilgrim) on Sep 07, 2002 at 12:21 UTC | |
by talexb (Chancellor) on Sep 07, 2002 at 22:34 UTC | |
by blakem (Monsignor) on Sep 07, 2002 at 23:45 UTC | |
by Flexx (Pilgrim) on Sep 08, 2002 at 22:11 UTC | |
|
Re: Re: Re: variable set to 0 ? 0 : 1
by jdporter (Paladin) on Nov 05, 2002 at 15:39 UTC |