Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
mobile ruleP2stack specificStack: kotlin
kotlinimmutabilityval
Prefer val over var; make state immutable by default
Declare with val unless reassignment is genuinely required; immutability prevents accidental mutation bugs.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codekotlin
| 1 | var total = items.sumOf { it.price } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codekotlin
| 1 | val total = items.sumOf { it.price } |
Explanation (EN)
Objašnjenje (HR)