Coding Standard Assignment Kit
Coding Standard Assignment Kit
Coding Standard
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
PSP Fundamentals
Prerequisites Prerequisites
Read Chapter 4
Coding Produce, document, and submit a completed coding standard that calls for
standard quality coding practices.
requirements
For LOC counting, ensure that a separate physical source line is used for each
logical line of code.
Submit the coding standard with your program 2 assignment package.
Coding standard Pages 5 and 6 of this workbook contain a C++ coding standard example.
example
Notes about the example:
Since it is an example, tailor it to meet your personal needs.
If you have an existing organizational standard, consider using it for the PSP
exercises.
Reuse - Describe how the program is used: declaration format, parameter values, types,
Instructions and formats.
- Provide warnings of illegal values, overflow conditions, or other conditions that
could potentially result in improper operation.
Reuse /******************************************************************/
Instruction /* Reuse instructions */
Example /* int PrintLine(char *line_of_character) */
/* Purpose: to print string, line_of_character, on one print line */
/* Limitations: the line length must not exceed LINE_LENGTH */
/* Return 0 if printer not ready to print, else 1 */
/******************************************************************/
Identifiers Use descriptive names for all variables, function names, constants, and other
identifiers. Avoid abbreviations or single-letter variables.
Identifier Int number_of_students; /* This is GOOD */
Example Float: x4, j, ftave; /* This is BAD */
Comments - Document the code so the reader can understand its operation.
- Comments should explain both the purpose and the behavior of the code.
- Comment variable declarations to indicate their purpose.
Good Comment If(record_count > limit) /* have all records been processed? */
Bad Comment If(record_count > limit) /* check if record count exceeds limit */
Major Sections Precede major program sections by a block comment that describes the processing
done in the next section.
Example /******************************************************************/
/* The program section examines the contents of the array grades and calcu- */
/* lates the average class grade.
*/
/******************************************************************/
Blank Spaces - Write programs with sufficient spacing so they do not appear crowded.
- Separate every program construct with at least one space.
Indenting - Indent each brace level from the preceding level.
- Open and close braces should be on lines by themselves and aligned.
Indenting while (miss_distance > threshold)
Example {
success_code = move_robot (target _location);
if (success_code == MOVE_FAILED)
{
printf(The robot move has failed.\n);
}
}
Capitalization - Capitalize all defines.
- Lowercase all other identifiers and reserved words.
- To make them readable, user messages may use mixed case.
Capitalization #define DEFAULT-NUMBER-OF-STUDENTS 15
Examples int class-size = DEFAULT-NUMBER-OF-STUDENTS;
Reuse - Describe how the program is used. Provide the declaration format, parameter values
Instructions 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 identifiers.
Avoid abbreviations or single letter variables.
Identifier Example
(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