return (messy) -vs- return clean

ok at edai.UUCP ok at edai.UUCP
Wed May 23 06:45:48 AEST 1984


    I never use return(expr) or return (expr) on the grounds that
it looks like a FUNCTION CALL, and it isn't.  Most of the time
you are saying return TRUE or return FALSE or return <variable>,
and the extra junk doesn't do anything for you.

    Do people who like return(e) also #define Goto(x) goto x
and then write Goto(L), Break(), Continue() and so on?  If not,
why not?

    I'd prefer keywords like if ... then instead of if (...).
This principle that things which aren't function calls shouldn't
look like function calls has lead me to adopt the practice of
	#define skip
	while (this_does_everything) skip;
instead of
	while (this_does_everything) ;
I apologise for letting code get out into the world without this
readability feature, and promise not to do it again.

    In all seriousness, the more parentheses there are in an
expression, the harder it is to read.  I personally find the
layout
	y = x == 5 ? 1 : 0;
much clearer than
	y = (x == 5) ? 1 : 0;
Yes, a policy of avoiding parentheses can make very large expressions
hard to read, but adding unnecessary parentheses only makes it worse;
the answer is to break up big expressions.  (That doesn't hurt most
compilers either.)



More information about the Comp.lang.c mailing list