A question of style

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Dec 5 17:40:47 AEST 1989


In article <680014 at hpmwjaa.HP.COM> jeffa at hpmwtd.HP.COM (Jeff Aguilera) writes:
->>while (c = getchar(), c != EOF)
-Too much annoying white space, conveying no information or structure.  Try
-    while (c=getchar(), c!=EOF)
-instead.  Pull atomic concepts and actions together.

I think most experienced programmers would prefer white space around
assignment operators.  I prefer whitespace around any infix binary
operator.  This is not terribly important anyway.

->The standard C idiom for this is
->    while ( (c = getchar()) != EOF )
-Gee.  I prefer the first construct.  Indeed, it is the only one I dare use, 
-because it is so much clearer.

Clarity must be in the eye of the beholder, because many programmers
find the standard idiom much clearer: "get a character into`c' and test
it against EOF".  With the form you prefer, one has to mentally connect
the two occurrences of `c' and appreciate that their contents are
related.  That connection is automatic to the experienced user of the
second form.

-But I understand (and accept) that most programmers are compelled to
-use the K&R form, following their masters' dogma blindly, criticizing
-all others.

You don't understand shit.



More information about the Comp.lang.c mailing list