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

B.J. herbison at ultra.DEC
Mon Apr 29 03:22:24 AEST 1985

> What do you mean, any criticisms?  This is one of the most ugly
> perversions of C I've ever seen!  I tend to read this in terms of
> "if variable equals constant" and try to figure out how the value
> "10" is ever going to change!  YUCK YUCK YUCK!!!!
> People that write "if (10 == j)" probably also write "while (1)".
> What do you mean, "while 1"???  Are you expecting "1" to change???
> Everyone knows this should be written "for (;;)", read "forever".
> 					Bill Shannon

I am glad that this discussion has been kept civil and that you restrained
from using emotional or personal attacks.  We wouldn't want net.lang.c to
be confused with net.flame or net.abortion.  Tell me Bill, is that how you
respond whenever someone makes a comment you don't agree with -- yelling
"YUCK YUCK YUCK" in their face?  I'm glad I don't work with you.

Personally, I don't like "while (1)", I much prefer "while (TRUE)",
just so it is obvious what is going on.
A much better solution, which explicitly says what is happening, is
    #define loop_forever <insert your favorite idiom here>

But back to the original topic.  "one of most ugly perversions of C"--
I tend to only use language this strong for things like the fact that
"=" is the assignment operator in C rather than a test for equality.
I am used to it, but it was a bad mistake and has cost thousands of
people tens of thousands of wasted hours in looking for the bugs it
has caused.  Using 'if (CONSTANT == j)...' [avoid putting magic numbers
in code, that can cause bugs also] seems like a way to help solve

In the meantime, try to avoid using code like 'if ((i+1) == (2*j))...',
some people (by their own admission) might not be able to handle a
comparison where neither side is a variable and neither side is a constant.

                                                Herbison%Ultra.DEC at decwrl.ARPA

More information about the Comp.lang.c mailing list