Poll on style issue in comparison

Dick Dunn rcd at opus.UUCP
Fri Sep 20 13:10:46 AEST 1985


I'd like to poll you folks on a small matter of style.  I've seen it
mentioned from time to time in lang.c.  PLEASE email (DON'T POST) answers
to the questions below; I'll post responses and comments in a bit.

The issue is this:  People tend to stumble over the difference between ==
and =.  It's not that they don't know the difference; they just screw up,
typically writing something like
	if (x=0) ...
when they mean
	if (x==0) ...
Some people have suggested reversing the order of comparisons, viz:
	if (0==x) ...
so that the compiler will complain if = is substituted for ==.
One argument against this form is that it is an unconventional order which
is harder to read.
- - - - - - - - - - - - - - - - - - - - - - - - - -
The questions:

1.  Do you use this form of comparison?

2.  Regardless of whether you use it, how do you feel about it (e.g., other
    people using it in code that you will maintain)?
	- dislike it
	- neutral (OK if you want to do it)
	- like it

3.  If you use or like this way of writing comparisons, how do you feel
    about also writing ordering tests with the constant first, as
	if (0<x) ...
    - dislike
    - neutral
    - like

Opinions welcome in addition to answers to the above; I'll summarize.
Again, please MAIL responses rather than posting them.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Lately it occurs to me what a long, strange trip it's been.



More information about the Comp.lang.c mailing list