Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!nrl-cmf!ukma!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Always use braces Message-ID: <9272@smoke.BRL.MIL> Date: 4 Jan 89 07:34:46 GMT References: <5@rsoft.UUCP> <1071@goofy.megatest.UUCP> <861@quintus.UUCP> <271@twwells.uucp> <11037@ulysses.homer.nj.att.com> <9235@smoke.BRL.MIL> <683@htsa.uucp> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 19 In article <683@htsa.uucp> fransvo@htsa.UUCP (Frans van Otten) writes: >In article <9235@smoke.BRL.MIL> gwyn@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...