In message <[EMAIL PROTECTED]> on Tue, 4 Dec 2007 00:06:29 -0600, "Matthew D. Fuller" <[EMAIL PROTECTED]> said:
fullermd> On Mon, Nov 26, 2007 at 11:52:00PM +0100 I heard the voice of fullermd> Rhialto, and lo! it spake thus: fullermd> > fullermd> > I read "if (x) ..." as "if there is an x, ..." which maps fullermd> > nicely to both integral and pointer types for x. fullermd> fullermd> See for instance in vscreen.c:CtwmSetVScreenMap(); saying fullermd> "if(tally==0)" would be a lot clearer than "if(!tally)"[0]. I don't agree with that, as tally clearly has a boolean intent. I agree with you, though, that 'tally' is completely unnecessary, and "if (!tally)" could as well be "if (buf[0] == '\0')". And speaking of style, I'm noticing that you and I differ when it comes to spaces around operators... fullermd> I certainly find that "if(foo==NULL)" is a lot more obvious fullermd> than "if(!foo)". I honestly don't see much difference, except if you want to be very explicit about foo being a pointer. fullermd> And don't get me started on when people writen fullermd> "if(!strcmp(...))", which means just the opposite of your fullermd> immediate impression. Explicit comparisons make it fullermd> immediately obvious what you're checking. That's misuse of a tristate value. It can't be used as a boolean. This is a case where I agree with you. fullermd> I read "if(x)" as "if x" and then have to take a mental fullermd> fault to figure out "if x... if x what?" If you know C (and no, your brain doesn't have to be a C compiler), the meaning is obvious. What is less obvious is if the author knew what he/she was doing, but that's a whole different matter... fullermd> a fair number of C coding standards I've seen mandate no fullermd> explicit comparison for obvious predicates, and require the fullermd> comparison when it's not). Actually, I like that. Now, all we need to clear is what constitutes the grey area of what is obvious and what is not. Cheers, Richard ----- Please consider sponsoring my work on free software. See http://www.free.lp.se/sponsoring.html for details. -- Richard Levitte [EMAIL PROTECTED] http://richard.levitte.org/ "When I became a man I put away childish things, including the fear of childishness and the desire to be very grown up." -- C.S. Lewis
