One more point regarding = and == (more flamage)

Andrew Koenig ark at alice.att.com
Sun Mar 24 05:01:54 AEST 1991


In article <3182 at inews.intel.com> bhoughto at pima.intel.com (Blair P. Houghton) writes:

> Basically, if you're worth the meager pittance they direct-deposit
> into your debt with the Company Store, the comments will have
> existed long before you wrote the code.  Put those in, and make
> them accurate, and it doesn't matter how much the code obfuscates.

Not everyone agrees that comments should explain what code does
on a line-by-line level.  The trouble is that if a comment restates
what an obvious piece of code does, then it's just clutter -- and
if it says something different from the code then something is
seriously wrong.

People bring me a lot of broken programs to help fix.  The first
thing I do when looking at such a program is to cover up the
comments and insist that the author not attempt to explain the
program to me.  All too often the bug has been that the code
misstated the author's intent, although that intent was correctly
stated in the comments.

Stragetic comments are extremely important: ``this section ensures
that database X reflects the changes made to database Y.''  Tactical
comments, however, are sometimes of negative worth.

As to the original question, I stand by the recommendation I
made in `C Traps and Pitfalls:' if you have an assignment as
the top-level operator in a test, such as if(a=b), rewriting it
as if((a=b)!=0) will make your intentions obvious in a way that
the original never will.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list