Code Style - gotonode/ohtu GitHub Wiki

This page lists all the coding style rules enforced by Checkstyle.

No magic numbers

This rule is currently NOT IN EFFECT.

A magic number is a number that is used in code that is not a -1, 0, 1 or 2. Magic numbers should be replaced with constants that are defined elsewhere.

Incorrect:

if (http.errorCode == 404) {
    something();
}

Correct:

private final int NOT_FOUD = 404; // This is a constant value and can never be changed once set.

if (http.errorCode == NOT_FOUND) {
    something();
}

Opening brace on the same line

We write the opening brace on the same line, not on the following line.

Incorrect:

if (true)
{
    something();
}

Correct:

if (true) {
    something();
}

String comparison using 'equals' instead of '=='

In Java, String comparison should be done using 'equals' and not by simply using '=='.

Incorrect:

String a = "meaning";
String b = "meaninglessness";
if (a == b) {
    something();
}

Correct:

String a = "meaning";
String b = "meaninglessness";
if (a.equals(b)) {
    something();
}