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 ruleP2universalStack: Kotlin
modelingnull-safetytypes
Model a binary state as a boolean/enum, not a nullable
When a value is inherently two-state (connected/disconnected, on/off), model it as a boolean or a two-case enum, not `T?`/nullable. A third `null` state that can never legitimately occur forces meaningless null handling everywhere and hides bugs behind an impossible case.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codekotlin
| 1 | val isConnected: Boolean? = null // what does null mean? |
Explanation (EN)
A nullable boolean invents a third state that has no real meaning for connectivity.
Objašnjenje (HR)
Good example
New codekotlin
| 1 | val isConnected: Boolean = false // start disconnected, then update |
Explanation (EN)
A plain boolean captures the two real states with a sensible default.
Objašnjenje (HR)