...
Table of Contents maxLevel 3
Indentation and spaces
Four spaces, NOT
tabsa tab character,
areis 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 (
if
,for
,catch
,
etc etc.), parenthesis, and braces, as well as when casting:Code Block language java 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 nameDevice
, and the class, something indicating that it implements theDevice
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 withInternal-
, e,gInternalClusterEventListener
. - Data types.
Wherever possible, use a rich data type over a primitive (e.g.MACAddress
versus along
). This reduces ambiguity. - Immutable objects.
Class variables should be declaredfinal
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.*
.
...