Skip to content

Kotlin code style

Alexander Yevsyukov edited this page Oct 21, 2023 · 10 revisions

Kotlin code of Spine SDK follows the standard conventions with the extensions and modifications described below.

Property names for constants

Kotlin conventions for property names encourage using SCREAMING_SNAKE_CASE for constant properties.

Unlike in Kotlin conventions, we prefer lowercaseCamelCase for naming such properties for two reasons:

1. Better readability

Compare "$group:$infix-fat-cli:$version" and "$GROUP:$INFIX-fat-cli:$VERSION". Uppercase constants attract more attention than real interesting text around them.

2. Flexibility to changes

This is more important than №1 above.

Suppose you have a dependency defined via constant that end up with interpolated string such as "$GROUP:$INFIX-fat-cli:$VERSION". The dependency is used in several modules of your project.

After some time, you figure out that the version to be used depends on some condition. So VERSION is no longer a const val but simply val, so, by standard convention, you need to rename it. In turn, the constant which previously defined the dependency is also no longer const val, but val, and also has to be renamed.

A slight extension of logic resulted in a cascade of changes.

Property names for dependency objects

Instead of Gradle version catalogs we declare dependencies as Kotlin objects.

See the io.spine.internal.dependency package under buildSrc of a Spine SDK subproject for details.

Versions and Maven coordinates of dependencies are defined using lowercaseCamelCase.

Clone this wiki locally