-
Notifications
You must be signed in to change notification settings - Fork 7
Coding Standards
PiPeep edited this page Sep 13, 2010
·
8 revisions
- Use (“hard”) tabs, not spaces (“soft” tabs) for indentation
- Standard Java programming styles apply (CamelCase for classes, camelCase for variables and functions, ALL_CAPS for constants)
- We generally try to wrap at the 80 character column, although this rule can be loose, but if you have a really long line, consider wrapping it.
- To quote Linus Torvalds, “If you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.”; although to be fair, he was referring to C, and classes take up one level of indentation, so make that 4.
public class ClassName { //CamelCase
private static final int CONSTANT = 0; //ALL_CAPS
private int value = 0; //camelCase
//set values outside of constructor where applicable
public ClassName() { //Cuddly-Curly-Braces
this(5); //avoid waste. If you already have another
//constructor, use it rather than re-writing one
}
public ClassName(int value) {
setValue(value); //Always call getter & setters within
}
//constructors are also camelCase, like variables
public void setValue(int value) {
this.value = value; //in the case of a naming conflict,
//we use 'this.' to address the global (vs. prefixes)
}
public int getValue() {
return value;
}
}
- The iRobot Create is referred to as “Create” or “The Create” (Eg. CreateMovementPlugin)
- A Lego-based-robot is loosely referred to as a “motor based drive train” (Eg. MotorMovementPlugin)
- Use a consistent verb tense (preferably present-tense).
An infinite number of monkeys typing into GNU emacs would never make a good program.
~Linus Torvalds, Linux 1.3.53 CodingStyle documentation