Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mandrill!gatech!uflorida!umd5!uvaarpa!virginia!uvacs!rwl
From: rwl@uvacs.CS.VIRGINIA.EDU (Ray Lubinsky)
Newsgroups: comp.lang.c
Subject: Re: Unnecessary parenthesis
Message-ID: <2520@uvacs.CS.VIRGINIA.EDU>
Date: 8 Jul 88 13:36:56 GMT
References: <326@marob.MASA.COM> <8209@brl-smoke.ARPA>
Organization: U.Va. CS in Charlottesville VA
Lines: 49

In article <8209@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes:
> My main objection to excessive parentheses is that they
> make the code less readable, not more.  There are a few
> cases where the C precedence rules run counter to intuition,
> and in such cases sparing use of technically redundant
> parentheses can help the code reader.  However, they should
> not be used just because the code WRITER is unsure.  (Most C
> programmers I know have a copy of the chart from K&R 1st Ed.
> p. 49 taped up near their terminal.)

When I read code I tend to browse, slowing down for the parts the require more
thought.  Something like

	if (a < b && b < c && c < d && d < e)

is going to stop my scanning a lot more often than

	if ((a < b) && (b < c) && (c < d) && (d < e))

NOT because I am unaware of C precedence rules but because the first example is
devoid of visual structure.  Maybe your eye can parse the first as easily as
the second, but I have to drop into look-at-it-more-closely mode.  If this
happens to often it reduces my overall comprehension of the code.  I'm sure
we'd both agree that the FULL parenthesization of the expression:

	if ((((a < b) && (b < c)) && (c < d)) && (d < e))

would be abominable -- in my case because it makes the expression hard to
scan without thinking about it.

As for the "return" business I think it's more clear that

	return a + b * c;

is returning a value when it's written as

	return(a + b * c);  OR EVEN  return(a+(b*c));

because in scanning mode I expect a non-void function to return an expression
and I catch the concept of here-is-an-expression a lot more quickly when I see
those entirely unnecessary parentheses.  I also think that entirely
unnecessary white space helps readability, but a little execess
parenthesization can be an acceptable substitute.

-- 
| Ray Lubinsky,                    UUCP:      ...!uunet!virginia!uvacs!rwl    |
| Department of                    BITNET:    rwl8y@virginia                  |
| Computer Science,                CSNET:     rwl@cs.virginia.edu  -OR-       |
| University of Virginia                      rwl%uvacs@uvaarpa.virginia.edu  |