Coding Standard Template
Purpose To guide the development of programs
Counting Standard ● Count each physical line as one LOC.
● Do not count blank lines and comment-only lines.
● Be consistent about what you put on each physical line.
Program Headers Begin all programs with a descriptive header.
Header Format
Contents Provide a summary of the contents.
Contents
Example
Reuse Instructions ● Describe how the program is used. Provide the declaration format,
parameter values and types, and parameter limits.
● Provide warnings of illegal values, overflow conditions, or other conditions
that could potentially result in improper operation.
Reuse Example
Identifiers Use descriptive names for all variables, function names, constants, and other
Coding Standard Template June 2010 2010 by Carnegie Mellon University
identifiers. Avoid abbreviations or single letter variables.
Identifier Example
(continued)
Coding Standard Template June 2010 2010 by Carnegie Mellon University
Coding Standard Template (continued)
Comments ● Document the code so that the reader can understand its operation.
● Comments should explain both the purpose and behavior of the code.
● Comment variable declarations to indicate their purpose.
Good Comment
Bad Comment
Major Sections Precede major program sections by a block comment that describes the
processing that is done in the next section
Example
Blank Spaces ● Write programs with sufficient spacing so they do not appear crowded.
● Separate every program construct with at least one space.
Indenting ● Indent every level of brace from the previous one.
● Open and closing braces should be on lines by themselves and aligned with
each other.
Indenting
Example
Capitalization ● Capitalized all defines.
● Lowercase all other identifiers and reserved words.
● Messages being output to the user can be mixed-case so as to make a clean
user presentation.
Capitalization
Example
Coding Standard Template June 2010 2010 by Carnegie Mellon University