Path: utzoo!utgpu!water!watmath!dalcs!garfield!john13 From: john13@garfield.UUCP (John Russell) Newsgroups: comp.lang.c Subject: Re: Implicit testing of 0 (was: == vs =) Summary: how to make your intentions clear Message-ID: <4439@garfield.UUCP> Date: 24 Jan 88 19:52:57 GMT References: <11216@brl-adm.ARPA> <2111@chinet.UUCP> <4403@garfield.UUCP> <3208@bunker.UUCP> <3484@ihlpf.ATT.COM> Reply-To: john13@garfield.UUCP (John Russell) Organization: Memorial University of Newfoundland, St. John's Lines: 38 (Haven't seen 3208@bunker yet in its entirety so I'll be brief) >In article <3208@bunker.UUCP> garys@bunker.UUCP (Gary M. Samuelson) writes: >.1. I don't find the implicit test for zero "distasteful" -- I find >. hard-to-read code distasteful. Actually, "taste" is irrelevant. >. Cost of development and cost of maintenance are. Hard-to-read >. code costs too much. I enjoy solving puzzles as much as the >. next guy, but programmers should be paid to write programs, >. not solve puzzles. Might I propose a solution then? /* do several assignments to either the success value or 0 if call fails */ if (x = y = z = a = b = c = fn()) ... else /* I know all my temp variables are set to 0 here */ ... /* test current value of function against expected value */ if (q == fn()) /* or if (fn() == q) which some people prefer */ ... This allows you to save a machine cycle here and there, and do other things that someone else might find hard to follow, without creating an unreadable program. I personally find it easier to type out a short comment than to stretch my fingers for extra parentheses, '!= 0', '!= NULL' etc; I use a single key macro to do the /* */ and leave the cursor in the middle. Positioning extra parentheses in the middle of some long expression has bitten me far more often than has = vs ==. John -- "You are lying scum!" -- member of Parliament James Fulton was expelled for saying this to Canadian Prime Minister Brian Mulroney; use of the word "lying" was deemed unparliamentary, although the "scum" was acceptable