Use of i++; Re: C programming style (actually commenting)

Frank Adams franka at mmintl.UUCP
Sat Jul 20 04:21:32 AEST 1985


In article <508 at oliveb.UUCP> jerry at oliveb.UUCP (Jerry Aguirre) writes:
>If you want ease of maintenance then concentrate on USEFUL comments.  My
>favorate non-comment is:
>	int debug;	/* true if debugging is enabled */
>or the ever popular:
>	i++;	/* increment i */
>
>Usually followed by a 3 page procedure with a cryptic name and no
>comments.  I mean is it really hard to figure out what the variable
>debug is used for?  I would really rather have a few lines at the top
>of each procedure telling what it does and what the arguments are.  It
>is usually easy to follow the code if you know why the procedure was
>called.  It's trying to follow the code when you don't know what it was
>called for or what its inputs are that is hard.

Broadly speaking, I agree with this.  But you should go a step further,
(especially for a 3+ page procedure) and put a comment at the top of
each logical section of the code.  This makes it easier to read the code
and figure out what the program does.  A comment on each line doesn't
(much) do this, because one can as easily read the code as the comments.
Only obscure statements need comments, which is why one puts a comment
on every line in assembler code.  (! :-)

>Languages don't write bad code, people do.

Yes, but some languages make it easy to write good code, and hard to write
bad code, while others do the opposite.

>				Jerry Aguirre @ Olivetti ATC
>{hplabs|fortune|idi|ihnp4|tolerant|allegra|tymix}!oliveb!jerry

		Frank Adams



More information about the Comp.lang.c mailing list