KO

Kotlin Defaults

Core Kotlin coding conventions

Details

Language / Topic
kotlinKotlin
Category
Style Guide

Rules

balanced
- Follow Kotlin coding conventions: `camelCase` for functions/properties, `PascalCase` for classes, `UPPER_CASE` for constants.
- Use `val` by default; `var` only when mutation is needed — Kotlin encourages immutability throughout.
- Use `data class` for DTOs and value objects — it generates `equals()`, `hashCode()`, `toString()`, and `copy()` automatically.
- Use data classes for value objects. Use sealed classes/interfaces for restricted type hierarchies.
- Use extension functions to add domain-specific behavior to types you don't own — prefer them over utility classes and inheritance.
- Use `when` expressions instead of `if`/`else` chains — they're exhaustive with sealed types.
- Use coroutines for async operations. Use `suspend` functions and structured concurrency with `CoroutineScope`.
- Use null-safe operators (`?.`, `?:`, `!!`) — avoid `!!` except in tests.