https://kotlinlang.org logo
Title
b

Ben Edwards

08/11/2022, 4:28 PM
Doing JetBrains Basic Kotlin and it does not like the formatting of the first 3 val statement.
fun main() {
    val min_sleep: Int = readln().toInt()
    val max_sleep: Int = readln().toInt()
    val hours_slept: Int = readln().toInt()

    println(
        if (hours_slept < min_sleep) {
            "Deficiency"
        } else if (hours_slept > max_sleep) {
            "Excess"
        } else {
            "Normal"
        }
    )
}
Variable names should match the pattern: [a-z][A-Za-z0-9]* What am I missing?
k

Kyle F Boon

08/11/2022, 4:30 PM
it doesn't like the underscores
minSleep
r

Robert Jaros

08/11/2022, 4:30 PM
Use "camel case" for variable names (minSleep).
b

Ben Edwards

08/11/2022, 4:32 PM
OK, thanks, just worked that out. A real shame, I find it a little less readable.
v

Vampire

08/11/2022, 4:43 PM
You can use any code style you want. snake_case is just not common for variable names in Kotlin (or also Java), so your code will look alien to any Kotlin or Java developer out there.
Most important is, that you are consistent within the same codebase
j

Johann Pardanaud

08/11/2022, 4:53 PM
and you can disable this inspection if you want
it could be useful if you are using underscores everywhere
j

jbnizet

08/11/2022, 5:46 PM
But your code will use external libraries (at least the Kotlin standard lib), which doesn’t use underscores. So using them, even consistently, within your code base will still make it an inconsistent mess. Just get into the habit of using the standard naming conventions.