RomRaider Code Style Guide - RomRaider/RomRaider GitHub Wiki
Code lay-out
Maximum Line Length
Limit all lines to a maximum of 79 characters.
There are still many devices around that are limited to 80 character lines; plus, limiting windows to 80 characters makes it possible to have several windows side-by-side. The default wrapping on such devices disrupts the visual structure of the code, making it more difficult to understand. Therefore, please limit all lines to a maximum of 79 characters. For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended.
The preferred way of wrapping long lines is by using Java's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. Make sure to indent the continued line appropriately. The preferred place to break around a binary operator is after the operator not before it.
Indentation
Use 4 spaces not tabs per indentation level.
Set your Editor defaults to enforce this, in Eclipse:
Window > Preferences > General > Editors > Text Editors
- Displayed Tab width: 4
- Insert spaces for tabs: selected
- Show Print Margin: selected
- Print margin column: 79
Window > Preferences > Java > Code Style > Formatter
Edit the Active Profile (which will make a new profile) and set:
- Tab policy: Spaces Only
- Indentation Size: 4
- Tab size: 4
Edit the name of the profile and press OK to save it and make it active.
Line Continuation
Continuation lines should align wrapped elements inside parentheses, brackets and braces using a hanging indent. When using a hanging indent the following considerations should be applied; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line. For example:
# Aligned with opening delimiter
final String result =
String.format("Plugin found: %s Serial: %d",
ik.getDeviceName(),
serial);
System.out.printf(result);
# or more indentation included to distinguish this from the rest.
final String result =
String.format(
"Plugin found: %s Serial: %d",
ik.getDeviceName(),
serial);
System.out.printf(result);
Blank Lines
Separate top-level function and class definitions with two blank lines.
Method definitions inside a class are separated by a single blank line.
Extra blank lines may be used (sparingly) to separate groups of related functions.
Use blank lines in functions, sparingly, to indicate logical sections.
Whitespace in Expressions and Statements
Use your own judgement; however, never use more than one space, and always have the same amount of whitespace on both sides of an operator.
Yes:
i = i + 1
submitted += 1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b)
No:
i=i+1
submitted +=1
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)