Poll on style issue in comparison
Alexis Dimitriadis
alexis at reed.UUCP
Sun Sep 29 16:07:25 AEST 1985
This is in response to an article asking about the proposed style of
comparisons where the constant is placed on the left, to eliminate
typos like
if (x=NULL)
> >1. Do you use this form of comparison?
>
> No.
As a matter of fact, I tried. I was rather intrigued when the subject
came up, so I thought I'd give it a go. One pleasant side effect is things
like
if (NULL == (fp = fopen("foo", "r")))
scream();
The above looks, to me at least, more readable than the other leading product.
The approach seems to work OK when testing for equality, but I felt that
consistency required that I use it in all tests. However, to reverse
if (foo > 0)
I have to write
if (0 < foo)
which is more than a little twisted. It may be my conditioning, but I _do_not
immediately perceive the two as equivalent. I stuck with it, but it
required extra effort to reverse the operators.
Another problem was, not all comparisons involve a hard constant.
Do we reverse
if (i == some.external->variable)
to convey the fact that we are testing the value of i? And so on.
A few weeks later I had to modify the program, and since I did not at
the time feel like going through the same, I put everything back the way
God meant it to be. Too bad, but mixing the two styles is a complete
no-no. If there weren't all that existing code that we all need to look at,
this style might stand a chance. It may have a chance if used for
equality tests only, but that is not as orthogonal.
I hope someone cared about my experience with this silly, but interesting
style.
-- Alexis Dimitriadis
--
_______________________________________________
As soon as I get a full time job, the opinions expressed above
will attach themselves to my employer, who will never be rid of
them again.
alexis @ reed
{decvax,ihnp4,ucbcad,uw-beaver}!tektronix!reed.UUCP
More information about the Comp.lang.c
mailing list