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, 1998

Last revision: 1/29/98

TABLE OF CONTENTS

Executive Summary *

1. File Naming Conventions *

2. Prologue Standards *

3. Symbol Naming Standards *

4. Commenting Standards *

5. Whitespace Standards *

6. Other Standards *

 

 

EXECUTIVE SUMMARY

 

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.

  1. File Naming Conventions
  2.  

    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.

     

  3. Prologue Standards
  4.  

    1. File Prologue Format

 

Each code file will have a prologue that fits the following format:

 

    1. A backslash followed by thirty asterisks.
    2. An empty line.
    3. The word "Filename:" followed by the name of the file.
    4. The words "Class List:" followed by a list of all classes defined in the file, the main class first (the main class being the class named the same as the file).
    5. The word "Description:" followed by a general description of the contents of the file.
    6. The word "Author:" followed by the name or names of programmers that contributed to the code.
    7. The word "Revisions:" followed by the day, month and year of the each change to the code and a brief description of the change.
    8. An empty line.
    9. Thirty asterisks followed by a backslash.

 

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)

 

******************************/

 

    1. Class Prologue Format

 

Every class description will have a prologue in the following format

 

    1. A backslash followed by thirty asterisks.
    2. An empty line.
    3. The word "Class:" followed by the name of the class.
    4. The word "Description:" followed by a brief description of the class.
    5. The word "Methods:" followed by a list of methods.
    6. The word "Author:" followed by the name of the programmer who wrote the class
    7. The word "Revisions:" followed by the day, month and year of each change to the code.
    8. An empty line.
    9. Thirty asterisks followed by a backslash.

 

Example:

/******************************

 

Class: List

Description: linked list class

Methods: Add

Delete

Find

Author: Matt Petro

Revisions: 12 Dec 97 Original Version

 

******************************/

 

    1. Module Prologue Format

 

Each Module (or Method) will have a prologue conforming to the following format:

 

    1. A backslash followed by ten asterisks.
    2. The word "Method:" followed by the name of the method.
    3. The word "Description:" followed by a brief description of what the method accomplishes.
    4. The word "Input Parameters:" followed by a list of input parameter types and names and an indication if the parameter is changed within the method.
    5. The word "Return Value:" followed by the return type. If the method does not return a value, the word "none" will be used.
    6. The word "Files Accessed:" followed by a list of files accessed or created by the method. If no files are accessed, the word "none" will be used.
    7. The word "Classes Accessed:" followed by a list of other classes and their methods called by this method. If no other classes or methods are accessed, the word "none" will be used.
    8. Ten asterisks followed by a backslash.

 

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

**********/

 

  1. Symbol Naming Standards
  2.  

    1. Variable Naming

 

Variable names will have the following characteristics:

    1. All lower case.
    2. Descriptive.
    3. Short as possible, keeping legibility and descriptiveness.
    4. Will not make use of underscores.

 

Example:

newlist

 

    1. Method Naming

 

Method names will have the following characteristics:

    1. Start with a capital letter.
    2. Will contain a new capitol letter for every new word in the name.
    3. Descriptive.
    4. Short as possible, keeping legibility and descriptiveness.
    5. Will not make use of underscores.

 

Example:

NewList()

 

    1. Constant Naming

 

Java lacks a preprocessor, so symbol constants are not allowed.

 

  1. Commenting Standards
  2.  

    1. Commenting Variables

 

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:

    1. Simple counter variables (e.g. for( int i = 0; i > 10; i++))

 

Example:

//Total is used to tally the number of node entries read

int total;

 

    1. Commenting Control Structures
    2.  

      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;

       

    3. Commenting Other Code Segments

 

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.

 

  1. Whitespace Standards
  2.  

    1. Indention Rules
    2.  

      Nested control structures will be indented three spaces for clarity.

       

    3. Usage of Blank Lines

     

    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.

     

  3. Other Standards
  4.  

    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.

     

    1. Global Variables
    2.  

      Use of global variables is discouraged.

       

    3. Function Length
    4.  

      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.

       

    5. Braces
    6.  

      Braces for blocks of code will be placed on their own lines to make tracing nested control structures clearer.

       

    7. Clarity vs. Brevity
    8.  

      Coding clarity will take precedence over brevity if a conflict arises.

       

    9. Operators
    10.  

      Spaces will be maintained between operators an their operands.

       

    11. Parenthesis

 

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.