When do you use "if ( a = b )"? (was Re: Funny mistake)

Michael Henning michi at ptcburp.ptcbu.oz.au
Tue Mar 19 16:25:20 AEST 1991


grover at sonny-boy.cs.unlv.edu (Kevin Grover) writes:

[ Stuff deleted I entirely agree with ]

>Also, if you get bitten but this bug often, try something like

>	#define EQU ==

>	if ( a EQU b)

>Instead of depending upon remembering to use '==' when you need to.

NO, NO, NO ! Please don't do this. There is nothing worse than a set of
macros that redefine the syntax of the language without achieving anything
else. Have you ever seen the original source for the Bourne shell ?
It is written with a set of macros that try to make it look like Algol.
Almost impossible to understand. Similarly, #defines like

#define	or	||
#define	and	&&
#define	not	!
#define	begin	{
#define	end	}

contribute nothing to the readability of the code, but make it worse (IMHO).
No matter who hard you try, C is not Pascal.

#define	EQU	==

falls into the same category. Granted, using = instead of == is a common
mistake, and people do get bitten. If C had used := and == instead, the
problem would not exist. Still, things are the way they are, and macros
to "improve" the language won't help. Much better to get used to the
deficiencies of C and to live with them. Simply say 1000 times:

	"I shalt never again use = instead of ==".

And besides, are you going to change every occurrence of == to EQU in every
piece of code you will ever maintain ?  I don't think that you would make
many friends that way, a lot of software maintenance relies on noise-free
diff listings.

					Michi.
-- 
      -m------- Michael Henning			+61 75 950255
    ---mmm----- Pyramid Technology		+61 75 522475 FAX
  -----mmmmm--- Research Park, Bond University	michi at ptcburp.ptcbu.oz.au
-------mmmmmmm- Gold Coast, Q 4229, AUSTRALIA	uunet!munnari!ptcburp.oz!michi



More information about the Comp.lang.c mailing list