Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!iuvax!ux1.cso.uiuc.edu!dino!hascall From: hascall@cs.iastate.edu (John Hascall) Newsgroups: comp.lang.c Subject: Re: C style peeve and knowing the rules Message-ID: <894@dino.cs.iastate.edu> Date: 25 Mar 90 18:34:00 GMT References: <2205@osc.COM> <340018@hplvli.HP.COM> <19356@megaron.cs.arizona.edu> Sender: usenet@dino.cs.iastate.edu Organization: Ministry of Silly Walks Lines: 36 robert@cs.arizona.edu (Robert J. Drabek) writes: }I require my students to use the absolute minimum number of parenthesis }until they have ALL the rules down pat. Operator precedence and associativity in C is quite complicated and somewhat non-intuitive. A few well-placed parentheses can go a long way toward promoting readability and understanding, even if they are not strictly necessary.[1] This mess has "the absolute minimum number of parentheses": a /= b ? c << 3 & g || f ? e || 2 + ++d & ~c : w : z; }Please, I know parenthesis are sometimes an aid in producing readable }code and they are also clutter which can make for less-readable code. Extra parenthesization, even full parenthesization need not be mutually exclusive with readability, that's what whitespace is for! a /= (b ? ( (((c << 3) & g) || f) ? ( (e || ((2 + ++d) & ~c)) : w ) : z ) ); But then, I'm not much for dogma, John Hascall (that's pronounced "throat warbler mangrove" :-) hascall@atanasoff.cs.iastate.edu ---------- [1] "Parentheses are not necessary around the first expression of a conditional expression, since the precedence of ?: is very low, just above assignment. They are advisable anyway, however, since they make the conditional part of the expression easier to see." (K&R1 p. 48)