Path: utzoo!mnetor!uunet!husc6!yale!bunker!garys From: garys@bunker.UUCP (Gary M. Samuelson) Newsgroups: comp.lang.c Subject: Re: == vs = Message-ID: <3208@bunker.UUCP> Date: 20 Jan 88 14:26:11 GMT References: <11216@brl-adm.ARPA> <2111@chinet.UUCP> <4403@garfield.UUCP> Reply-To: garys@bunker.UUCP (Gary M. Samuelson) Organization: Bunker Ramo, an Olivetti Company, Shelton, Ct Lines: 43 In article <4403@garfield.UUCP> john13@garfield.UUCP (John Russell) writes: >I made the = mistake a couple of times very early in the C learning process. >But since I convinced myself that "if (x = fn())" was both a valid and >useful construct, and put it to use in code, the *meaning* of each has become >very apparent so that I use the proper form automatically. > >People who find the implicit test for zero distasteful (I get the feeling >many of them never programmed in assembler) may never be comfortable with >'=='. But for people who like it for its conciseness, the chances of using >the wrong symbol due to a typo should be no greater than typing "mian" instead >of "main". 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. 2. It is irrelevant whether I have programmed in assembly. As it happens, I have. I'm very good at it, and I write both assembly and C according to the "write for the reader" principle. 3. I don't buy the "conciseness" argument -- In the first place, 1 character is not significantly more concise than 2. In the second, "conciseness" is only a virtue, in my opinion, to the extent that it provides readability. 4. While it may be true that typing "mian" for "main" is as likely as typing "=" for "==", the linker will tell me that I mispelled "main" by reporting "undefined symbol." Neither the compiler, the linker, nor lint (of which I am an ardent advocate) will tell me if "=" should be "==". 5. When I see "if (x = fn())", I know what it means, but sometimes I am not sure whether the author meant "if (x = fn())" or "if (x == fn())". I spend a lot of time trying to figure out what other programmers meant, even after I figure out what they wrote. "if( (x = fn()) != 0 )" is longer, but it is totally unambiguous to both the author and the (human) reader. Gary Samuelson