Subject: Re: Parentheses and KNF
To: Brian C. Grayson <bgrayson@marvin.ece.utexas.edu>
From: John F. Woods <jfw@jfwhome.funhouse.com>
List: current-users
Date: 08/19/1998 21:08:09
>
>  Can _anyone_ parse that in 5 seconds or less, or should
> the comment and the example be changed/updated?  :)

Nah, leave the example, then add one word and some new punctuation:

        /*
         * Unary operators don't require spaces, binary operators do. Don't
         * use parenthesis unless they're required for precedence, or the
         * statement is really confusing without them, like:
         */
        a = b->c[0] + ~d == (e || f) || g && h ? i : j >> 1;

(Myself, I would feel entirely justified parenthesizing that as

        a = ( (b->c[0] + ~d == (e || f)) || (g && h) ) ? i : (j >> 1);

IN PARTICULAR because I had to go look in The Bible[*] to be absolutely
certain how the logical operators group.  Parenthesizing (j >> 1) is, I think
a little less necessary, but it makes for a consistent appearance.)

[*] K&R II, of course.  (A copy with handwritten corrections, like "noalias
went.  It was non-negotiable.")