We will be following the CS400 style guide for programming in Java.
- Be consistent.
- Names should use camelCase.
- Method names that are over 3 words in length should use underscores.
- Names should of course be relevant to their function.
- Classes, interfaces, exception types should start with a capital letter.
- interfaces
- public interface SearchTreeADT {}
- classes
- public class BalancedSearchTree {}
- exception types
- EmptyQueueException
- fields
- private int heightOfTree;
- methods
- public void test01_isEmpty_on_empty_tree() {}
- public String toString() {}
- parameters
- (Treenode rootOfSubtree)
- local variables
- int leftNodeIndex;
- instance constants
- private final double exponentIncrement;
- class constants
- private static final double piValue = 3.14;
- Be consistent.
- Comments should be descriptive and concise to increase readability.
- In-line comments should have descriptions for complex blocks of code and algorithms.
- Comments for public members of classes.
- Comments should add information to otherwise obscure blocks of code.
- Javadoc for methods is not required and optional.
-
classes
- // inner node class to store key items and links to other nodes
- protected class Treenode<K extends Comparable> {}
-
fields
- // pointer node to parent node of current state
- private State pointer;
-
constructors
- // constructs a Treenode with item as key and null for left and right children
- public Treenode(K item) {
- this(item, null, null);
- }
-
methods
- // rotates subtree of node left using algorithm from class
- private Treenode leftRot(Treenode node) {}
-
coding style (brackets, horizontal, and vertical spacing) for:
- if statements
- if(( bool && (3 >= 5)) || !boolValue) {
- intValue = 5;
- } else {
- return;
- }
- if(( bool && (3 >= 5)) || !boolValue) {
- switch statement
- switch (month) {
- case 1: monthString = "January";
- break;
- case 2: monthString = "February";
- break;
- default: monthString = "Invalid month";
- break;
- case 1: monthString = "January";
- }
- switch (month) {
- while loops
- while(true) {
- intValue++;
- }
- while(true) {
- for loops
- for(int i = 0; i < str.length; i++) {
- array.add(i);
- }
- for(int i = 0; i < str.length; i++) {
- enhanced for loops
- for(State successor : successors) {
- stack.push(successor);
- }
- for(State successor : successors) {
- if statements