Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site columbia.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!columbia!dupuy From: dupuy@columbia.UUCP (Alex Dupuy) Newsgroups: net.lang.c Subject: Re: condition convention 'if (10 == j)...' Message-ID: <505@columbia.UUCP> Date: Sun, 28-Apr-85 11:27:32 EDT Article-I.D.: columbia.505 Posted: Sun Apr 28 11:27:32 1985 Date-Received: Mon, 29-Apr-85 07:24:34 EDT References: <137@bocklin.UUCP> <1456@amdahl.UUCP> <2140@sun.uucp> Reply-To: dupuy@columbia.UUCP (Alex Dupuy) Organization: Columbia University Lines: 49 In article <2140@sun.uucp> shannon@sun.uucp (Bill Shannon) writes: > > > To prevent silly mistakes like > > > if (j = 10) > > > I usually write > > > if (10 == j) > > > By putting the constant first, I ensure that the compiler will catch the > > > typo. > > > > [Flames...] > > People that write "if (10 == j)" probably also write "while (1)". > What do you mean, "while 1"??? Are you expecting "1" to change??? > Everyone knows this should be written "for (;;)", read "forever". > > Bill Shannon I agree that "if (10 == j)" looks ridiculous, but to prevent ridiculous errors like "if (j = 10)" /* j is set to 10 */ or "if (j != NULL & j->next != NULL)" /* bitwise AND evaluates j _and_ j->next even if j is nil */ and to make my code more human readable (:-) I use the following #definitions: #define and && #define or || #define is == #define isnt != #define not ! As a result, my code looks like "if (j is 10)" "if (j isnt NULL and j->next isnt NULL)" which even Pascal types (like me) can read. And there is *no* way to make those silly mistakes shown above. I even throw in another: #define ever ;; so I can have *real* "for (ever)" loops. Alexander Dupuy Ok, go ahead and flame me for not being a strict K&R type who likes C to look like a mess of proofreaders marks (and if you think this isn't "heretical" enough, you should see my indentation style :-).