Skip to content

1.1.3 Identation

Tomaz Martins edited this page Jul 31, 2015 · 2 revisions

1.1.3.1 Line Length

The lines should not exceed a length of 80 characters, as above that the lines are no longer handled by many terminals and tools.

1.1.3.2 Wrap Lines

When an expression does not fit on a single line should break it in according to the following general principles:

  • Break after some point.
  • Break after an operator.
  • Align the new line to the beginning of the expression at the same level line above.

Below are some examples of expressions breaking quite common in Call methods.

sum (firstParcel, secondParcel,
         thirdParcel, name);

total = sum (firstParcel, secondParcel,
                 thirdParcel, name);

Below follows some example of how one should treat a line break some arithmetic expression containing parentheses.

sum + = firstParcel (secondParcel + 4) +
         thirdParcel + 7;

It ends the expression inside the parentheses before the line break.

For the declaration of methods follows the following conventions, if necessary line break.

public void someMethod (firstParameter int, int secondParameter,
         thirdParameter int, String fourthParameter);

For instructions on if use the indentation following:

// Do not use this indentation ...
if ((firstParcel> secondParcel)
         || (Sum <fourthParcel)) {
         sum 3 + 4;
}

// Use this indentation!
if ((firstParcel> secondParcel)
             || (Sum <fourthParcel)) {
         sum 3 + 4;
}

The second is preferable as it avoids confusion with the instructions follow instructions within the body of the if.