forked from konrad-jamrozik/droidmate
-
Notifications
You must be signed in to change notification settings - Fork 14
Styleguide
natanieljr edited this page Jul 31, 2018
·
4 revisions
We primarily use Kotlin and follow the standard coding conventions outlined in https://kotlinlang.org/docs/reference/coding-conventions.html
The following outlines the most important aspects.
- Place curly braces in the end of the line where the construct begins and the closing brace on a separated line aligned vertically with the opening construct.
if (elements != null) {
for (element in elements) {
// ...
}
}
- Put spaces around binary operators
(a + b)
- Do not put spaces around unary operators
(a++)
- Put spaces between control flow keywords
(if, when, for and while)
and the corresponding opening parenthesis. - Put a space after
//
:// This is a comment
Put a space before :
in the following cases:
- when it's used to separate a type and a supertype
- when delegating to a superclass constructor or a different constructor of the same class
- after the
object
keyword
Don't put a space before :
when it separates a declaration and its type.
abstract class Foo<out T : Any> : IFoo {
abstract fun foo(a: Int): T
}
class FooImpl : Foo() {
constructor(x: String) : this(x) {
//...
}
val x = object : IFoo { ... }
}
Can be discussed
- For longer documentation comments, place the opening
/**
on a separate line and begin each subsequent line with an asterisk - Start the sentence with an upper case letter, unless the grammar forbids.
- Finish the comment with a point.
/**
* This is a documentation comment
* on multiple lines.
*/
Short comments can be placed on a single line:
/** This is a short documentation comment. */
Use a single class per file, unless otherwise required (e.g. for sealed classes and their sub-classes)