C/C++ Programming Style Guidelines
to describe any variable whose purpose is not obvious from its name.
should be obvious from the implementation. Instead describe why your code does what
it does. Avoid explaining especially tricky code in comments. Instead, rewrite the code
to make it intrinsically more obvious. Use complete sentences with proper spelling and
punctuation in all comments.
writing comments you give yourself a low-level design for the implementation. When
you are finished testing your code, go back and review all comments to make sure they
are still accurate.
condition of variable on input, document that. If a required speed optimization makes
the code difficult to read, explain the need for the code in a comment. If your code uses
or changes any global variables, comment that.
implement a number of private utility functions. Use a bold comment to mark the start
of that code. Preface each function with a block comment describing the function's
purpose, the meaning of any input variables, and the significance of any return value(s).
There is no need to include the function name since it immediately follows the
comment.