Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles $Revision: 1.7.0.5 $; site ccvaxa Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!inuxc!pur-ee!uiucdcs!ccvaxa!seefromline From: preece@ccvaxa.UUCP Newsgroups: net.lang.c Subject: Re: Use of expression values in C Message-ID: <2600006@ccvaxa> Date: Tue, 16-Jul-85 10:26:00 EDT Article-I.D.: ccvaxa.2600006 Posted: Tue Jul 16 10:26:00 1985 Date-Received: Thu, 18-Jul-85 05:34:15 EDT References: <5764@utzoo.UUCP> Lines: 25 Nf-ID: #R:utzoo.UUCP:-576400:ccvaxa:2600006:000:1149 Nf-From: ccvaxa.UUCP!preece Jul 16 09:26:00 1985 > For those who think "if ((foo=fopen(filename,"r"))==NULL) { ... }" > is hard to understand, why not create a macro to handle this: > #define opentest(filename,mode,ptr) ((ptr=fopen(filename,mode)==NULL) > and then you can write "if (opentest(filename, "r", foo)) { ... }" ---------- Unfortunately, the name 'opentest' doesn't imply that the variable named 'foo' has been set to the new fd and that the file is now open. It implies (to me, at least) a test of whether it is possible to open the file. Now, if you wanted to call it "TRY_TO_OPEN", I would be more likely to interpret the name correctly, but some people might interpret that name as a Boolean indicating whether or not to try to open the file. Naming is very tricky. Doing the operation is very clear. There's always room to argue about whether a particular expression is too complex. In this case I don't think anyone would have difficulty with the original form. The insightful programmer tries to notice and simplify expressions that are likely to be a problem. Arbitrary rules are unlikely to be satisfying. -- scott preece gould/csd - urbana ihnp4!uiucdcs!ccvaxa!preece