> My untested (and consequently firmly
> held) hypothesis is that
>
> 1) most combinations of && and || don't need parentheses because
>
>       (a && b) || (c && d)
>
> is by far more common than
>
>       a && (b || c) && d
>
> and, moreover, broken code fails at runtime, and

I dispute these claims.

The former may be statistically more common, but I'd be surprised if the 
difference is that big. I can think of several fairly common situations where 
both would be used.

Any time you've got any sort of nontrivial condition, I always find it better 
to include the explicit parentheses. Especially if a, b, c, and d are 
relatively complex relational expressions rather than simple variables.

Code failing at runtime is way too late.  By that time it's already been 
burned onto the device, and may be half way to the moon :-)
Coverage testing never tests everything, and there's a fair chance that your 
complex condition will only break in an exceptional case which is, by 
definition, hard to predict, test and reproduce.

> 2) Most programmers know (because they need to know) that && comes
> before ||. 

I don't really believe that either. Most *good* programmers know operator 
precedence rules (or will at least look it up). However there are a lot of 
distinctly average programmers, and even the good programmers get confused or 
have bad days. As someone else mentioned precedence of arithmetic operators 
is taught in school from a fairly early age. Precedence of logical operators 
is (to me at least) much less well conditioned.


I have no objection to splitting -Wparentheses into finer grained options. I 
just think they should remain enabled by -Wall.

Paul

Reply via email to