Kotlin Android Coding standards

Vokal Specific Standards

Vokal follows Android's Kotlin style guide. Below are additional guidelines we follow.

Nullability

As a rule of thumb, !! should never be used and ? should be used rarely. Theses checks can often be avoided and doing so will provide for a more stable code-base. Whenever possible, objects and properties should be made to be not nullable.

Activities / Fragments

Always import the synthetic layouts for your activity or fragment. This cuts down on an immense amount of boilerplate and keeps your code clean.

Always prefer Kotlin-esque direct property accesses whenever available:

Do this:

myTextView.text = "Hello, ${user.firstName}!"
myTextView.visibility = View.VISIBLE

Not this:

myTextView.setText("Hello, ${user.firstName}!")
myTextView.setVisibility(View.VISIBLE)
Annotations

Annotations should appear above a class definition, and inline if it is annotating a field in a class:

Do this:

@Root(strict=false)
public open class User (
    @field:Element public open var firstName: String? = "",
    @field:Element public open var lastName: String? = "",
) {}

Not this:

@Root(strict=false) public open class User (
    @field:Element
    public open var firstName: String? = "",
    @field:Element
    public open var lastName: String? = "",
) {}

More information

For more information about the language see their site
or view the documentation

For Android specific resources visit Kotlin in Android page