-
Notifications
You must be signed in to change notification settings - Fork 35
Vert.x code style guidelines
All Java code code in the vertx-core
repository or any repositories under the vert-x3
organisation must adhere to this guidelines.
Any non Java code should try and remain as to close to them as possible, where appropriate.
Our guidelines should be familiar to most developers as they are pretty much the IntelliJ defaults / Oracle codestyle guidelines with some minor changes. So they're pretty much defacto standard Java code style anyway.
We recommend that all repos should have a .editorconfig
in the root folder with at least the following content:
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
Having such file will out of the box allow you to follow the basic guidelines regarding line ending, spacing, tabs in IntelliJ and many other IDE's and for IDE's that do not support it out of the box there are plugins.
Fundamentally you should be able to infer the guidelines just by looking at the current code in a master
branch. However for clarity here they are:
We use a variation of the 1TBS 1TBS (One True Brace Style) - this is basically a variation of K&R style, and is characterised by breaking after the opening brace of a code block, including classes Here is an example:
class Foo {
void aMethod(int x) {
if (x == 3) {
doSomething();
} else {
doSomethingElse();
}
}
}
We never use tabs, only spaces. Number of spaces in an indent is always 2. We use this small number because there's sometimes quite a lot of nested indents in callback based code.
We generally don't use a lot whitespace, e.g. blank lines between code. But feel free to use them where they aid clarity. Don't go overboard.
Do this:
if (x == 3) {
}
Don't do this:
if (x==3) {
}
Or this:
if ( x == 3 ) {
}
Or this:
if ( x==3 ) {
}
Do this:
for (int i = 0; i < 10; i++) {
}
Not this:
for (int i = 0;i < 10;i++) {
}
Max page width is 120 chars, not 80. We don't program on green screens or print stuff using line printers any more.