Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site reed.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!ucbvax!decvax!tektronix!reed!alexis From: alexis@reed.UUCP (Alexis Dimitriadis) Newsgroups: net.lang.c Subject: Re: Poll on style issue in comparison Message-ID: <1941@reed.UUCP> Date: Sun, 29-Sep-85 02:07:25 EDT Article-I.D.: reed.1941 Posted: Sun Sep 29 02:07:25 1985 Date-Received: Wed, 2-Oct-85 05:46:48 EDT References: <1702@brl-tgr.ARPA> Reply-To: alexis@reed.UUCP (Alexis Dimitriadis) Organization: Reed College, Portland, Oregon Lines: 43 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