condition convention 'if (10 == j)...'

Goldilocks lspirkov at udenva.UUCP
Tue Apr 30 03:00:27 AEST 1985


In article <> gam at amdahl.UUCP (G A Moffett) 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.
>
>I think this is a good idea.  Any criticisms?  The only problem
>I have with it is that I am not accustomed to reading code written
>this way.
>-- 
>Gordon A. Moffett

yeah, it does seem very odd to ask if 10 equals something else.
after all, 10 == 10 and nothing else.  j is the variable.
it's easy to think the other way around.

i have a friend that uses macros to avoid the silly mistake.
instead of saying
	if (j == 10)
he defines a macro IS and says
	if (j IS 10). 
-- 

					Goldi

email:  udenva!lspirkov



More information about the Comp.lang.c mailing list