Coding Conventions

This is the general coding convention used in this project. To ensure a consistent style throughout the project, please follow these guidelines.

General
/************************** * Description: What this is for and how to use * Pre-conditions: What is needed * Post-conditions: What are the results **************************/ Examples: package CodeConvention; import CodeConvention.Numbers; import CodeConvention.XmlParser; import java.util.ArrayList; /****************** * Class Name: ExampleCode * Description: Dummy code to demonstrate coding conventions * Last Modified: Nov. 9th 2008 * Last Modified by: Davie ******************/ private int MAX = 50; public class ExampleCode { public void styleDemo( String parameter ){ for ( int i = 0; i < MAX; i++ ){ if (i == someNumber) { System.out.println("Do this"); }            else { System.out.println("Do something else"); }            try { ...            }             catch ( Exception e ) { ...            }         }     }     public void secondMethod{ ...    } //code continues here } //EOF
 * Group imports by package and order alphabetically
 * Separate loops/switch/if-else blocks with a single blank line
 * Separate methods with two blank lines
 * Separate different code functions into class files
 * Use a 4-space tab
 * Use consistent naming for variables that gets passed across classes and methods.
 * Indent all code that is part of a block
 * Match braces indentation of the block
 * Add the following comment block for complex methods
 * Insert space after "(" and before ")" for parameters
 * End files with //EOF tag

Files
Example: Renderer.java SaveFileLoader.java
 * Use camel case for file names as opposed to underscores, starting with a upper case character
 * Use a descriptive name so that the name properly describes what it does

Test Classes

 * unit test class names should begin with the name of the class being test followed by the word test
 * unit test names should begin with the word test followed by the name of the original method

Headers
/****************** * Class Name: * Description: * Last Modified: * Last Modified by: ******************/
 * Use this header comments at the top of each class file

Constants
Examples: double PI = 3.14159625; String[] INNERPLANETS = {"Venus", "Mercury", "Earth", "Mars"} int DELAY = 10000;
 * Use ONLY upper case for constants
 * Use descriptive naming for the constant

Variables
Examples: myVariable, aVariable, thisIsMySuperLongVariableName, etc.
 * Use camel case for variable names as opposed to underscores, starting with a lower case character

Examples: stepCounter, firstName, dateOfBirth, saveDataHashString, saveFileTokenizedString, etc. Not: lol, var1, asdf, n834, etc.
 * Use descriptive names so that it properly describes the variable

Examples: public int swap (int firstInt, int secondInt) { int a; a = firstInt; firstInt = secondInt; secondInt = a; }
 * For temporary variables use a single character variable.

Examples: int iNumberOfLines String sUserName SaveFile sfLoadedSaveFile
 * Prefix the variable with the object type in lower case

Examples: String[] sPlayerNamesArr ArrayList miMenuItemsArrLst
 * Suffix the variable when the variable is a collection of a type of variable.

Methods
Example: public String getUserName (int UserId) { return this.sUserName; }
 * Use camel case for method names as opposed to underscores, starting with a lower case character
 * Open braces on the same line as declaration

Comments

 * Use comments to describe a certain logic or what the code does if it isn't dead obvious
 * Use comments for workarounds/hacks to get something to work properly to prevent removal of the code during code reviews
 * Use comments to signify end of file with //EOF
 * Do not use a single line comment that goes beyond the screen's width, break it up into multiple lines instead