Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Code Standards

ajtgarber edited this page Jan 9, 2013 · 7 revisions

Classes - UpperCamelCase

Class names should give a hint as to what the class does, while still avoiding being overly verbose.

Variables - private/public/locals - lowerCamelCase

Variables - static/finals/anything that behaves like a constant - MAX_POWER

Methods - lowerCamelCase

Comment things using javadoc specification. Make comments useful, as a word of advice (okay.. maybe several) if you feel that you need to make a comment try your best to rewrite the code so the comment is no longer necessary but write a useful comment anyway just for clarity.

/** 
 * @returns Returns true forever and ever
 * @param foo the parameter of the function 
 */
public boolean isOn(boolean foo)
{
    return true; //This always returns true
}

Further javadoc notation is detailed at the oracle site, [here.] (http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#format)

Singletons: In order to handle singleton classes (ex. subclasses of Subsystem) the class should hold a static instance of it's own type, and implement a method named getInstance that will either return the static variable (if it's not null), or construct and then return that variable. The constructor must be private to allow only the getInstance method access to it. Example (yay code!)

public class Test extends BadSubsystem {
     public static Test instance;
     public static Test getInstance() {
          if(instance == null)
              instance = new Test();
          return instance;
     }

     private Test() {
          //...
     }
     //...
}