You are previewing Code Complete, Second Edition.

Code Complete, Second Edition

Cover of Code Complete, Second Edition by Steve McConnell Published by Microsoft Press
O'Reilly logo

Commenting Techniques

Commenting is amenable to several different techniques depending on the level to which the comments apply: program, file, routine, paragraph, or individual line.

Commenting Individual Lines

In good code, the need to comment individual lines of code is rare. Here are two possible reasons a line of code would need a comment:

  • The single line is complicated enough to need an explanation.

  • The single line once had an error, and you want a record of the error.

Here are some guidelines for commenting a line of code:

Avoid self-indulgent comments. Many years ago, I heard the story of a maintenance programmer who was called out of bed to fix a malfunctioning program. The program's author had left the company and couldn't be reached. The ...

The best content for your career. Discover unlimited learning on demand for around $1/day.