On Sat, Feb 20, 2010 at 4:49 PM, Trevor Orr <[email protected]> wrote:
> My preference is to always use the { } no matter how many statements to
> execute in an if statement.  What are do the rest of you use?

A few years ago I would avoid braces where they weren't necessary,
thinking that the code was less cluttered and more elegant.

Like others who've replied, I no longer think that way -- it's better
to be clear and concise with code, both for sharing with other
developers and for one's own benefit down the road.  (I usually find
"down the road" to be a few days or weeks later when I'm working out
some kind of unexpected behaviour and end up adding else's to my if
statements anyway.)

A number of authors I've read over the last 20-25 years also refer to
a 6 month rule in some manner or another - if you won't be able to
read your own code in 6 months, it's not fit [and/or to share].

By always using the braces, even when it's not strictly necessary,
there is less room for misinterpreting the relevant section of code.

-- 
  Scott Elcomb
  http://www.psema4.com/   @psema4

  Member of the Pirate Party of Canada
  http://www.pirateparty.ca/

Reply via email to