-
Notifications
You must be signed in to change notification settings - Fork 20
Code guidelines
Ivan Schütz edited this page Mar 23, 2020
·
11 revisions
- Use Kotlin.
- Keep it simple!
- Keep functions and classes reasonably short.
- Minimize side effects.
- Avoid force unwrap (
!!
) andlateinit
. If needed, use?: throw Exception("Meaningful message")
. - Use extensions.
- If they are shared, put them in a file <ClassName>Extensions (e.g. TextFieldExtensions.kt)
- If they are specific to a class/file, make them private.
- Use idiomatic Kotlin (
let
,apply
,also
, etc.). But keep readability in mind! Often a simpleif != null
is better. - Prefer composition over inheritance.
- Prefer immutability.
- Prefer explicit type declarations for instance variables.
- Use readable names.
- If something is difficult to understand, add some documentation.
- Use Rx in services / repos / business logic / view models and live data only to interface with the UI.