This style guide outlines the style used for all code written in Java in DXRAM and all related projects. We would like to keep this style consistent across all projects. Instead of writing down all the rules we want you to follow when contributing to our projects, please use the formatter.xml file with IntelliJ included in the repository.
Furthermore, please use the inspections.xml file with IntelliJ. It includes a lot of very useful warnings that highlight common mistakes and also enforce some rules to enhance overall code quality.
There are a few additional rules that cannot be enforced by the formatter but want you to stick to:
Types of control blocks: if, if-else, for, while, do-while, try-catch
// bad
value = 1;
if (value == 0) {
value = 1;
}
value++;
// good
value = 1;
if (value == 0) {
value = 1;
}
value++;
Comments that describe the control block are ok to "stick" to it:
// good
value = 1;
// sets value to 1
if (value == 0) {
value = 1;
}
value++;
// bad
int myFunc() {
int var = 1;
return var++;
}
// good
int myFunc() {
int var = 1;
return var++;
}
// bad
void myFunc(int p_v1, bool p_v2) {
// ...
}
// good
void myFunc(final int v1, final bool p_v2) {
// ...
}
// bad
if (var == 1) {
while (true) {
// ...
}
}
// good
if (var == 1) {
while (true) {
// ...
}
}
// good
if (var == 1) {
// comment
while (true) {
// ...
}
}
However, if the control blocks starts with a statement, make sure to add an empty line afterwards if followed by another control block.
// bad
if (var == 1) {
int var2 = 2;
while (true) {
// ...
}
}
// good
if (var == 1) {
int var2 = 2;
while (true) {
// ...
}
}
// good
if (var == 1) {
int var2 = 2;
// comment
while (true) {
// ...
}
}