Skip to content

Code Style Guidlines

CodingRat edited this page Nov 21, 2017 · 1 revision

This page is still a draft

The source code follows, for the most part, standard Java style guidelines. This page describes places where it differs. Please, make sure that your pull requests follow these guidelines closely.

Formatting

Placement of braces

You should follow the Allman indentation style. That is, braces are placed in a new line. They are optional for single-line blocks. Lines should be indented with 4 spaces, not tabs. For example:

public void onClick() { something(); somethingElse(); }

Method complexity

Methods should be short, self-documented and not nested very deeply. In general, methods should have no more than 15 lines, and contain no more than two sub-levels (for example, one for loop inside an if block). You should not include comments to explain what certain sections of your code are doing. If you feel the need to do this, your methods are probably too long, and should be broken down into smaller and more self-evident methods.

Null pointer exceptions

Unexpected things being null is probably the most frequent source of crashes on the app. Because of that, any new code must use the @Nullable and @NonNull annotations anywhere possible. That is, every non-primitive field in every class, as well as every non-primitive parameter in every method, must be marked either as @Nullable or as @NonNull. When using external libraries and framework calls, it should be assumed that everything returned or provided is @Nullable, unless explicitly documented otherwise. Pull requests adding null checks to old code are very welcome.