US Software Capstone Design Project
GNAT - Graphical Network Analysis Tool
Coding Standards
Design Team:
Matt Ericson
John Kobinski
Matt Petro
Rob Waltz
Client:
Rich Ames, US Software
v1.0
January 29, 1998Last revision: 1/29/98
Executive Summary *
1. File Naming Conventions
*2. Prologue Standards
*3. Symbol Naming Standards
*4. Commenting Standards
*5. Whitespace Standards
*6. Other Standards
*
This document covers the coding standards and requirements that will be used by the US Software Capstone design team. It includes file and function headers, symbol naming conventions, commenting standards, whitespace standards, and several miscellaneous rules and suggestions for programmers.
File naming conventions will follow the form imposed by the Java language. All class files must have the same name as the main class contained therein. File extensions for class files are ".java". User manuals or technical documents will have descriptive names and the file extension ".doc". Output files in the Snoop2 format will have a user defined file name with the required ".snp" extension. Text file output will have a user defined file name with the file extension ".txt". Other types of output files will have a descriptive name and a file extension that suits the format.
Each code file will have a prologue that fits the following format:
Example:
/******************************
Filename: Gui.java
Class List: Gui
Package
Data
Description: This file contains the classes used to graphically interface the GNAT software with a user.
Author: Matt Ericson
Revisions: 12 Dec 97 Original Version
20 Dec 97 Added Help Window
7 Jan 98 Allowed for multiple About Boxes (Global Variables)
******************************/
Every class description will have a prologue in the following format
Example:
/******************************
Class: List
Description: linked list class
Methods: Add
Delete
Find
Author: Matt Petro
Revisions: 12 Dec 97 Original Version
******************************/
Each Module (or Method) will have a prologue conforming to the following format:
Example:
/**********
Method: Add
Description: Adds a node to a linked list. Returns true if successful, false if unsuccessful.
Input Parameters: node new
list nodelist
Return Value: boolean
Files Accessed: none
Classes Accessed: none
**********/
Variable names will have the following characteristics:
Example:
newlist
Method names will have the following characteristics:
Example:
NewList()
Java lacks a preprocessor, so symbol constants are not allowed.
All variables will be commented upon initialization. The comment will explain the function of the variable to the class or method and will take the form of double backslashes before each comment line. The following exceptions are allowed:
Example:
//Total is used to tally the number of node entries read
int total;
Every control structure will be commented. The comment will explain the logic performed by the control structure. The comment will precede the control structure and will take the form of double backslashes before each comment line.
Example:
//Exit if total nodes are counted, else continue
if ( total = nodenum )
return;
Structures, methods, and I/O handling will all be well commented. The comment will precede the code and will explain the codes function and any peculiarities or difficulties contained therein. The comment will take the form of a double backslash preceding each comment line.
Large, complex, or peculiar blocks of code will be commented at the programmer’s discretion. Code legibility and intelligibility will be maintained throughout.
Nested control structures will be indented three spaces for clarity.
Blank lines will be used to separate classes in a file. They can also be used internal to a class to separate code into logical blocks.
The following are guidelines to programmers, and can be broken if circumstances demand. Clear, clean code shall be maintained, and deviation from these guidelines should be well commented as to the reason and effects of the deviation.
Use of global variables is discouraged.
Functions of excessive length should be avoided. As a rule of thumb, any function in excess of 200 LOC will be considered long. Long functions should be evaluated to see if it is possible or desirable to break into sub-functions.
Braces for blocks of code will be placed on their own lines to make tracing nested control structures clearer.
Coding clarity will take precedence over brevity if a conflict arises.
Spaces will be maintained between operators an their operands.
Liberal use of parenthesis is encouraged, unless over use would cause the code to become unclear. As a rule of thumb, any code string involving more than three operands and/or two operators with different precedence should be clarified by parenthesis. Spaces should be maintained between parenthesis and their contents.