zen-of-kotlinlisted
Install: claude install-skill sureshg/skills
# Zen of Kotlin
Guiding principles for writing clear, correct, and maintainable Kotlin code.
## Make Illegal States Unrepresentable
Model invariants in types so invalid data cannot compile or be constructed.
- When a domain is genuinely closed, use sealed hierarchies (`sealed interface` / `sealed class`) with exhaustive `when` branches.
- Represent optionality explicitly with nullable types (`T?`) and eliminate ambiguity at boundaries.
- Use strongly typed value wrappers (e.g., `@JvmInline value class`) instead of raw primitives.
- Scope resources correctly (`use { ... }`) so leaks are impossible in normal control flow.
## No Mutability by Default
Prefer `val` over `var`, and immutable data structures over mutable ones.
- Write pure functions first; keep side effects at the edge of the system.
- Express state changes as new values (`copy(...)`) instead of in-place mutation.
- Isolate unavoidable effects behind small interfaces so behavior stays testable.
## Make Data Types and Functions Domain-Oriented
Name types and operations in the language of the domain, not infrastructure.
- Replace primitive obsession with domain-specific types (`CustomerId`, `Email`, `Money`, etc.).
- Parse, then model: convert untrusted input at boundaries into validated domain values.
- Keep domain logic in domain types/functions; keep transport and persistence concerns outside.
## Prefer Composition, Expressiveness, and Clarity
Use small, composable functions and extension functions when