Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!apple!netcom!amdcad!dgcad!dg-rtp!gamecock!hagins From: hagins@gamecock.rtp.dg.com (Jody Hagins) Newsgroups: comp.lang.c Subject: Re: One more point regarding = and == (more flamage) Message-ID: <1991Mar22.161333.24290@dg-rtp.dg.com> Date: 22 Mar 91 16:13:33 GMT References: <13603@helios.TAMU.EDU> Sender: usenet@dg-rtp.dg.com (Usenet Administration) Reply-To: hagins@gamecock.rtp.dg.com (Jody Hagins) Organization: Data General Corporation, Research Triangle Park, NC Lines: 57 In article <13603@helios.TAMU.EDU>, byron@archone.tamu.edu (Byron Rakitzis) writes: |> I have one more thing to say to the self-styled C gods who approve of |> simple assignments as an implicit test against zero inside an if-statment. |> |> It's this: There is no way when you see the code-fragment |> |> a) while (*foo++ = *bar++) |> |> to tell whether a copy of data in strcpy fashion is intended, or whether |> this should have been a strcmp-like loop: |> |> while (*foo++ == *bar++) |> |> One is forced to gather from the context of the program just what the |> programmer intended. Now in this case, it may be "obvious" what the |> intent of the programmer is, but I don't think anyone can doubt that |> the first instance is rendered UNAMBIGUOUS by the addition: |> |> b) while ((*foo++ = *bar++) != 0) |> |> |> All I can say is, if you code in style (a) rather than style (b), don't |> expect anyone reading your code to enjoy the experience. |> |> Henry, are you behind me on this one? What do the coding style people say |> anyway? |> Well, I'm not Henry, but I definitely agree here! Also, Borland seems to agree here as well, since while(*foo++ = *bar++); will generate a warning message. One point here: Why go to the bother of commenting your code if you use statements like this? These seem counterproductive. I know, I know, comments will tell you what the meaning of the code is, but by using the comparison to 0, you do not have to specify in your comment that you, in fact, meant to use '=' instead of '=='. Also, (b) sure does make the code alot easier to maintain, especially when the maintainer is not the original developer. Why use comments when you refuse to use good style? You might as well write all your code in BASIC! You know, there is an example in the Bible about this. Paul had to confront the converts to Christianity who still insisted that every male had to be circumcised. He was indignant that they still held to part of "the old law." He says in Galations 5:12 (NIV) "As for those agitators, I wish they would go the whole way and emasculate themselves!" Now, I'm not saying that those who want to keep their bad programming habits must emasculate (efeminate ;-) themselves, but if the shoe fits... :-):-):-) -- Jody Hagins hagins@gamecock.rtp.dg.com Data General Corp. 62 Alexander Dr. RTP, N.C. 27709 (919) 248-6035 Nothing I ever say reflects the opinions of DGC.