A question of style
Chip Salzenberg
chip at ateng.com
Tue Dec 12 03:40:28 AEST 1989
According to tps at chem.ucsd.edu (Tom Stockfisch):
>I think the point here is that style evolves, and wouldn't if people never
>strayed from K&R. For instance, what if I justified my use of
>
> while (*s++ = *t++)
> ;
>
>by quoting K&R (I p. 101, II p. 106)?
You're right. Style evolves. However, stylistic evolution based on common
errors is different from arbitrary changes based on personal preference.
Your example contains an assignment used as a boolean value, which is a
questionable practice at best, due to the possibility of "="/"==" error.
So the alternative "while ((*s++ = *t++) != 0) {}" is demonstrably better.
On the other hand, I'd say that "c=getchar(), c!=EOF" provides little, if
any, benefit over "(c = getchar()) != EOF". It has the advantage of fewer
parentheses, true, but it has the disadvantage of multiple references to
the single variable. In my opinion, it's not a worthwhile tradeoff.
>Perhaps it is just because I have never learned lisp, but what *I* find
>most difficult to read are multiple sets of parentheses.
I hate LISP, aka Lots of Irritating Stupid Parentheses. But we're not
talking brain surgery here. My getchar() expression nests only one level
deeper than "c=getchar(), c!=EOF". I usually parse it visually this way:
if ((c = getchar()) != EOF)
^ open^ ^ ^close
two open two close
>Am I the only person who is slowed down by lots of parentheses?
Idioms are easy to parse once you're used to them. Use tricks, as above.
--
You may redistribute this article only to those who may freely do likewise.
Chip Salzenberg at A T Engineering; <chip at ateng.com> or <uunet!ateng!chip>
"The Usenet, in a very real sense, does not exist."
More information about the Comp.lang.c
mailing list