== vs =

Henry Spencer henry at utzoo.uucp
Sun Feb 7 15:36:48 AEST 1988


> To reiterate, compilers should not complain about style, only about
> marginally legal statements.

The trouble is that the boundary is fuzzy here.  Me, I want the compiler
to tell me when I've done something wrong and keep quiet when I've done
something right, but the definitions of "wrong" and "right" are tricky
and not necessarily the same for everyone.

What I decided, when faced with a similar situation once, was to have two
classes of such messages:  warnings and quibbles.  Warnings were for things
that were likely to be errors; they were on by default but could be turned
off.  Quibbles were for things that were odd but not necessarily wrong; they
were available on request but not by default.  The choice *is* a judgement
call in some cases, and depends slightly on your user community.

>		if (x = y) foo();
>
>		while (foo() > 0);
>			bar();
>
>		i = 1<<n - 1;

I would class all of these as warnings, because in each case there is a
high probability that it is an error.  If the bar() were at the same indent
level as the while, or the spaces were rearranged properly in the shift
example, then they would turn into quibbles.

It's quite true that such a set of decisions is, to some degree, a matter of
personal style.  However, to my dying day I will fight the idiot notion that
"there is no such thing as bad style, only different style".  All of the
above examples are thoroughly bad style, not just different but inferior:
they are dangerous, error-prone, hard-to-follow constructs that should be
avoided like the plague.  Even when the situation is not this extreme,
though, there are solid objective arguments for using a standard style
in anything that somebody else might have to maintain one day.  The phrase
"anyone should be able to understand that" is the mark of the amateur, more
concerned about his own preferences than his successors' problems.  And
if the code is strictly private, it's the work of a moment to come up with
a shell file that invokes the compiler with warnings suppressed (or grepped
out if it comes to that!).
-- 
Those who do not understand Unix are |  Henry Spencer @ U of Toronto Zoology
condemned to reinvent it, poorly.    | {allegra,ihnp4,decvax,utai}!utzoo!henry



More information about the Comp.lang.c mailing list