Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel3

Indentation and spaces

  • Four spacesNOT

     tabs

     a tab character,

    are

    is used for regular indentation. For code acrid multiple lines, eight spaces are used indent lines after the first:

    Code Block
    if (obj instanceof DefaultDevice) {
        return Objects.equals(this.id, other.id) &&
                Objects.equals(this.type, other.type) &&
                Objects.equals(this.manufacturer, other.manufacturer);


  • Trailing whitespaces should be removed in both code and comments.
  • There should be a space between keywords (ifforcatch, etc etc.), parenthesis, and braces, as well as when casting:

    Code Block
    languagejava
    if (timer != null) {
        try {
            DeviceId did = (DeviceId) elementId;
            ...
        } catch (IOException e) {
    ...
  • There should be a space before the curly braces in method definitions. Arguments are not padded (neither in definition nor invocation):

    Code Block
    public Device getDevice(DeviceId deviceId) {
        return store.getDevice(deviceId);
    }

...

  • Naming. 
    Interfaces should always be given first pick of clear names that convey their purpose.  For example, if there is an interface representing a network device, and a class implementing it, the interface should be given the name Device, and the class, something indicating that it implements the Device interface, e.g. DefaultDevice.

  • Referencing.
    Wherever possible, references should be made to the interface, and not the implementing class. This includes method parameters. 

  • Nested classes.
    A class that implements functions specific to a particular class (e.g. its event handlers or services that it exports) should be implemented as an inner private class within the class. Such classes have names beginning with Internal-, e,g InternalClusterEventListener

  • Data types.
    Wherever possible, use a rich data type over a primitive (e.g. MACAddress versus a long). This reduces ambiguity.

  • Immutable objects.
    Class variables should be declared final for classes that are intended to be instantiated as immutable objects (e.g. DefaultDevice).

Logging

The codebase uses SLF4J for logging. DO NOT use System.out.*

...