8 Coding Standard Assignment Kit
8 Coding Standard Assignment Kit
Coding/Counting Standard
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
PSP Fundamentals
Coding/Counting Standard
June 2012
PSP Fundamentals
Assignment Kit for the Coding/Counting Standard
Overview
Topics
See Page
Prerequisites
Objectives
Prerequisites
Prerequisites
Read Chapter 4
Objectives
Coding/counting
standard
requirements
Coding/Counting Standard
June 2012
Coding/Counting Standard
June 2012
Contents
Contents
Example
(continued)
Coding/Counting Standard
June 2012
Reuse
Instruction
Example
Identifiers
Identifier
Example
Comments
Good Comment
Bad Comment
Major Sections
Example
Blank Spaces
Indenting
Indenting
Example
Capitalization
Capitalization
Examples
Coding/Counting Standard
- Describe how the program is used: declaration format, parameter values, types,
and formats.
- Provide warnings of illegal values, overflow conditions, or other conditions that
could potentially result in improper operation.
/******************************************************************
/
/* Reuse instructions
*/
/*
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
*/
/******************************************************************
/
Use descriptive names for all variables, function names, constants, and other
identifiers. Avoid abbreviations or single-letter variables.
Int number_of_students;
/* This is GOOD */
Float: x4, j, ftave;
/* This is BAD */
- 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.
If(record_count > limit) /* have all records been processed?
*/
If(record_count > limit) /* check if record count exceeds limit
*/
Precede major program sections by a block comment that describes the processing
done in the next section.
/******************************************************************
/
/* The program section examines the contents of the array grades and calcu- */
/* lates the average class grade.
*/
/******************************************************************
/
- Write programs with sufficient spacing so they do not appear crowded.
- Separate every program construct with at least one space.
- Indent each brace level from the preceding level.
- Open and close braces should be on lines by themselves and aligned.
while (miss_distance > threshold)
{
success_code = move_robot (target _location);
if (success_code == MOVE_FAILED)
{
printf(The robot move has failed.\n);
}
}
- Capitalize all defines.
- Lowercase all other identifiers and reserved words.
- To make them readable, user messages may use mixed case.
#define DEFAULT-NUMBER-OF-STUDENTS 15
int class-size = DEFAULT-NUMBER-OF-STUDENTS;
June 2012
Suggestions
Coding/Counting Standard
June 2012
Counting
Standard
Program Headers
Header Format
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 identifiers.
Avoid abbreviations or single letter variables.
Identifier Example
(continued)
Coding/Counting Standard
June 2012
- 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
Indenting
each
Indenting
Example
Capitalization
Capitalization
Example
Coding/Counting Standard
June 2012