C Coding Standards Checklist
[ ] Indent source code in a manner consistent with the logical
structure of the code.
[ ] Indent comments the same amount as the code they describe.
[ ] Four spaces should be used as the unit of indentation. Never place
tab characters in source code files.
[ ] Avoid lines longer than 80 characters.
[ ] Open-close brace pairs must always be vertically aligned.
[ ] Each line contains at most one simple statement.
[ ] Braces are used around all statements, even single statements, when
they are part of a control structure, such as an
[ ] One blank line is used in the following circumstances:
- Between functions
- Between the local variables in a function and its first statement
- Before a block or single-line comment
- Between logical sections inside a function to improve readability
[ ] All comments should be clear, correctly spelled, grammatically
correct, and use simple English phrases.
[ ] Comments should be meaningful and relevant. They should assist
the reader in comprehending the code by adding
helpful annotations. Avoid comments that do not significantly enhance
readability and comprehension. The comment should not simply restate
[ ] Comment any statement whose intent is not immediately obvious.
[ ] Every control structure has a descriptive comment on the preceding
[ ] Each declaration must be on a separate line and must have an
comment. Variables local to a function may use end-of-line
[ ] In most cases, initialize local variables where they're
The only reason not to initialize a variable where it's declared is if
the initial value depends on some computation occurring first.
int level; /* indentation level */
int size; /* size of table */
[ ] Put declarations only at the beginning of blocks. Don't wait to
declare variables until their first use. The one exception to the rule
is indexes of for loops, which in C can be declared in the
[ ] The header block should contain the program name, student name, and
[ ] Functions Function names should be verbs or verb phrases,
mixed case with the first letter lowercase, with the first letter of
internal word capitalized. Examples: run();
getBackground(); findTotalCost(int Years);
[ ] Variables Variable names are nouns that succinctly
information as possible about what the object is.
[ ] Choose names that are "psychologically distant."
E.g. int total1, total2; would be better as int
[ ] One-character variable names are not allowed.
[ ] Don't assign several variables to the same value in a single
[ ] Use for only for counting loops, not conditional loops.
[ ] Never use break or continue in a loop.
[ ] Never compare a boolean value (or boolean function call) to a
[ ] Make the structure of your program match the intent.
NEVER DO THIS:
It is much clearer and simpler to write:
[ ] There should be no redundant code.
[ ] Decompose the problem into appropriate subprograms.
[ ] Subprograms must be cohesive. (Pg 175).
[ ] Design subprograms with appropriate parameters and return type.
use global variables.
[ ] Use structured flow-of-control constructs.