Always use braces
Doug Gwyn
gwyn at smoke.BRL.MIL
Wed Jan 4 17:34:46 AEST 1989
In article <683 at htsa.uucp> fransvo at htsa.UUCP (Frans van Otten) writes:
>In article <9235 at smoke.BRL.MIL> gwyn at brl.arpa writes:
>> #define MAGIC '\0' /* silly terminating character value */
>How do you like it my way:
> while ((ch = getchar()) != EOF && c) /* find EOF or '\0' */
>Any C programmer will understand how this function works; it takes less
>space, because it is shorter, etc. So: Why is my solution too simple ?
There is more to programming than simply writing code to short-range
specs. My approach has the following practical advantages:
1) The role of the "magic" terminating character is clear.
2) It is easier to comprehend, because the different return
conditions are clearly spelled out.
3) Questionable points of the design were flagged. In a real
project, these would be investigated and probably revised.
4) If the magic character ever needs to be changed, it is easy
to do in my version, and virtually impossible to go wrong.
If this sounds like an ad for Kernighan & Plauger's "The Elements of
Programming Style", well...
More information about the Comp.lang.c
mailing list