Avoid Overusing Defaults


Advice

Be cautious about using default arguments in data types or constructors - they can reduce safety, clarity, and discoverability in your code.


Context

Defaults are convenient, but they come with hidden trade-offs.

Defaults can potentially hurt

Finally, in layered architectures, defaults often blur boundaries. A data-transfer object should not know business rules — if the backend decides what’s “default”, let the backend populate it explicitly.


Examples

Good

data class BlogPost(
    val title: String,
    val tags: List<String>,
    val isBehindPaywall: Boolean
)

Bad

data class BlogPost(
    val title: String,
    val tags: List<String> = emptyList(),
    val isBehindPaywall: Boolean = false
)