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!linus!philabs!cmcl2!seismo!hao!hplabs!tektronix!reed!alexis From: alexis@reed.UUCP (Alexis Dimitriadis) Newsgroups: net.lang.c Subject: Re: constructs like if (NULL == (fp = fopen("foo", "r"))) Message-ID: <1983@reed.UUCP> Date: Tue, 8-Oct-85 22:57:48 EDT Article-I.D.: reed.1983 Posted: Tue Oct 8 22:57:48 1985 Date-Received: Fri, 11-Oct-85 08:40:53 EDT References: <1702@brl-tgr.ARPA> <1941@reed.UUCP> <173@l5.uucp> Reply-To: alexis@reed.UUCP (Alexis Dimitriadis) Organization: Reed College, Portland, Oregon Lines: 39 In article <173@l5.uucp> laura@l5.UUCP (Laura Creighton) writes: > The reason I found out that I hate this style is because I see a strong > conection between statements like: > > if (fp = fopen("foo", "r")) == NULL) > > and ones like > > fp = NULL; > > that is to say, mentally I have a strong binding between ``this is a > known value that I want to test things against'' and ``this is a known > value that I want to assign my variable to''. You are not alone, of course. Most people, including myself, write comparisons with the lvalue (or the "interesting" variable, when neither side is a constant) on the left. But,, inverting the terms for comparison was suggested precisely to distinguish it from assignment. (It would certainly defeat the purpose if you started writing assignments backwards as well!) Comparison is different from assignment (some would say _very_ different), and if we can make them look distinct without loss of clarity somewhere else, why, we should!! Actually, I said I found if (NULL == (fp = fopen("foo", "r"))) less convoluted than if ((fp = fopen("foo", "r")) == NULL) simply because the function call and its arguments do not get between the terms of the comparison (fp and NULL). Anyway, in my code I use the "standard" form, because it is. 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