By: | David R. Tribble |
Version: | 1.00, 1998-04-16 |
This treatise does not, in any way, attempt to resolve or dispute the religious wars concerning "good", "bad", or "ugly" programming style. What it does do is describe the particular programming style used in the set of source code created by the author. As such, it is intended to be used as guide for other authors, especially those who want to add to or otherwise enhance the original source code.
Comments are the most important thing about source code. True, a good architecture and a sound object model are the raison d´être for a set of programs, but comments are the soul of the implementation as embodied in the source code itself. Shoddy, insufficient, or excessive commenting clouds the soul of a program, no matter how well it functions.
C.1 Comment Lexicon
Source code uses the "//
" style of comments
rather than the "/**/
" style.
This is a little bit easier to read and
makes the source lines a tad bit shorter.
Example:
A few exceptions are allowed for this rule.
In particular, short comments embedded in the middle of
source lines require the use of the "/**/
" style of comments.
Example:
C.2 Comment Grammar
Comments are complete sentences, and begin with capitalized words. Exceptions to these rules are allowed, such as eliminating redundant "noise" words like "the". The case of variable and functions names is never altered in comments even if they occur as the first word of a sentence (since C++ is a case-sensitive language). Such names should usually appear within single quotes (e.g., 'count'), especially if their appearance would otherwise make the sentence confusing.
Example:
Variable, function, constant, and type names are quoted within comments (so that they are not confused with regular words).
Example:
C.3 File Comments
Every file begins with a block comment containing the following items:
3.1
, 3.10
, and 3.2
.
This also facilitates more effective lexicographical sorting.
YYYY-MM-DD
.
The last line of the file is a simple comment containing the name of the file. (This is useful when perusing printouts since it serves as a visual indicator of the end of the file.)
Example:
C.4 Function Comments
Every function definition is preceded by a block comment containing the following items:
Example:
I.1 Indenting
Statements are indented using spaces (not tabs). Each level of indentation is exactly four spaces.
Example (spaces are shown by the "°
" symbol):
T.1 Alignment
Tabs are used only to align source text. Tabs are never used for indentation.
Example (tabs are shown by the "¶
" symbol,
and spaces are shown by the "°
" symbol):
T.2 Newlines
Blank lines are used to separate groups of statements.
Example (empty lines are shown by the "¶
" symbol):
Double newlines are used to separate declaration groups and function definitions.
Example (empty lines are shown by the "¶
" symbol):
Copyright ©1998, by David R. Tribble, all rights reserved.
The views expressed herein represent only those of the author
and no one else.