Indentation, spaces and braces
The following rules outline the formatting guidelines for indentation and braces: Ø Indentation should be 4 space characters (tabs usage is prohibited). Ø Open brace should reside on the same line as related construct. Ø Case labels should use indentation. Ø All flow control primitives (if, else, while, for, do, switch) shall be followed by braces, even if they have single operation. Ø Methods, fields and nested types should be separated by single empty line. Related fields can be placed on the sequential lines however. Ø When instruction spares several lines, second and subsequent ones should be indented with 4 space characters. Ø If necessary, method logic can contain empty lines if it increases understandability (however, small methods strongly encouraged). For example: public class Point extends EventArgs { private final double x; private final double y;
public Point(double x, double y) { this.x = x; this.y = y; }
public double getX() { return x; }
public double getY() { return y; }
public PointType getType() { double radius = x * x + y * y;
if (Math.abs(radius – 1.0) < 0.000001) { return PointType.PERIODIC; }
if (radius < 1.0) { return PointType.CONVERGING; }
return PointType.DIVERGENT; } }
|