https://kotlinlang.org logo
Title
o

oblakr24

12/18/2017, 9:12 AM
Quick question: enum classes naming: capitalized (Swift-style) or all-caps (Java-style)? I don't see it stated explicitly in https://kotlinlang.org/docs/reference/enum-classes.html, and I prefer capitalized (because the editor already does a good-enough color-markup to distinguish it, and all-caps looks ugly)
s

sindrenm

12/18/2017, 9:29 AM
Hmm, good question! I've mostly written enums with all-caps style (
Color.RED
). But since enums aren't necessarily constant (i.e. immutable), I'm actually leaning towards pascal-casing them. However, I believe this to be inherited from Java, and since it's not really defined otherwise anywhere, I'd guess most people would use the Java conventions here. Think I might be up for a change, though.
Also, Kotlin brings sealed classes to the table. Now, being classes, they should definitely be named with PascalCase. But they do share some resemblance with enums as well, in that they're part of a finite group of related types. (Some people even call them “enums on steroids”.) So having the same conventions for sealed classes and enums would make some kind of sense in my mind. 🤔
h

hho

12/18/2017, 9:44 AM
The page you linked shows how it's done: The enum class is a class an therefore capitalized (
Color
) while the enum values are constants and therefore all-caps (
RED
). Also, that way interoperability with Java is preserved best.
s

sindrenm

12/18/2017, 9:44 AM
Also, that way interoperability with Java is preserved best.
I approve of this point. 👍
h

hho

12/18/2017, 10:02 AM
Indeed very interesting. I wonder why they don't put that on enum reference page.
s

sindrenm

12/18/2017, 10:03 AM
Good question. I guess they will soon, though, considering that issue. 👍