"Robert Gustavsson" <robert.gustavsson / bigfoot.com> writes:

> > The Pragmatic Pragma: use parantheses around method arguments!
> 
> Since reading the book Writing Solid Code a couple of years ago I've always
> used parentheses around expressions and arguments in languages where it is
> optional to avoid ambiguities and stupid mistakes with precendences. I've
> made it a part of my programming style to use parentheses in all expressions
> so I never need to hesitate how the expression will be interpreted/compiled
> except for +-*/ operators. For example:
> 
> if( (true == fExpression) && (true == fInHeader) )

Of course this doesn't always do what you mean in C or C++... I'd
personally find

  if (fExpression && fInHeader)

clearer.

> When learning and developing my Ruby style I've been a bit lazy and skipped
> the parentheses now and then.
> 
> Some sample code:
> 
> if strOutput =~ /^\s*'/ and 0 == indentLevel

Personally I don't think that's lazy, I think it communicates
better.

In general, I tend to add parens only when things get
complex. However... things _are_ complex when it comes to parsing
method arguments. What does

    Math.sin a + b

mean?

    Math.sin(a) + b
or
    Math.sin(a + b)          # <<< HINT <<<

Having been bitten more than once by this, I now alwaysuse
parentheses when my method arguments are anything other than a simple
list.


Dave


Footnotes: 
 almost