Coding Style Guide
-
class naming
-
lower case words with first character capitalized, first word is capitalized
eg SecureTransfer.java
-
variables
-
sections seperated by blank line
-
ordering
-
constants (static final)
-
GUI components
-
variants
-
naming
-
constants in capitals, underscore for spaces
-
variants are lower case words with first character capitalized, first word
is not capitalized eg prevPtr
-
methods
-
seperation of three lines between methods, middle line being composed of 75
dashes (-) commented out in /* */ fashion
-
ordering
-
constructors first
-
initGUI if applicable
-
top-down design (top-end functions placed first)
-
naming
-
lower case words with first character capitalized, first word is not
capitalized eg initGui
-
error messages & log writing
-
all error messages are handle through a single message class
-
log writing should be done by accessing the class logger
-
formating
-
80 characters per line
-
For method declarations with openned brackets, new line flush with
openning backet. See below
-
For other method declarations (ie throw clauses) place the clause tab
indented once past the method name.
-
tab indentation of 4 spaces
-
operators seperated by spaces (eg x = 1 + 8;)
-
where there is a comma, there is always a space after it, ie in method
declarations
-
catch statements are on the same line as the closing brace of the try clause
-
Imports are explicitly specified. ie import java.awt.event.ActionListener; and are grouped in one block (no blank lines).
-
comments
-
Java Doc'ing done in adherance to
the official java doc guide
-
One line comments to be handled using /* */
-
Line terminated comments to be handled by //
-
One line if needed explaining what each code block does.
-
No comments inside codeblock unless explicitly require (perhaps split code
block?)
Example code
/*---------------------------------------------------------------------------*/
/** Java Doc comment goes here */
method name (int x, int y, int z,
int colour) {
constant decs;
GUI compents;
variable decs;
code block 1;
try {
code block 2;
} catch {
code block 3;
}
return;
}