Kotlin

Kotlin

Made by DeepSource

Found function that only returns a constant KT-W1052

Anti-pattern
Minor

In Kotlin, it is generally preferred to use a constant variable instead of a function returning a single constant for improved code clarity, performance, and maintainability. Constant variables are more readable, avoid unnecessary runtime overhead, and enable centralized value management. Additionally, they allow potential compiler optimizations and promote code consistency. While using a function for a single constant may have certain specific use cases, the convention in Kotlin is to use constant variables.

Bad Practice

fun functionReturningConstantString() = "1"

Recommended

Instead, prefer declaring the constant as a const val.

const val constantString = "1"