How much do others follow the coding conventions? ...
# getting-started
t
How much do others follow the coding conventions? In particular the property names directives? https://kotlinlang.org/docs/coding-conventions.html#property-names A colleague trying to make any yellow triangles in the IDE go away ended up with:
Copy code
private const val ROW_COUNT = 3
private val oneWeek = 7.days
(used for a 7x3 calendar view) This seems undesirable/inconsistent to me. I would personally prefer that top level "globals" were consistent in some fashion. Am I the only other renegade out there? Or are others just ignoring these warnings?
y
Personally, I go with normal camel case even for constants. I think something being a constant usually isn't so relevant that I need it to scream it at me. The convention comes AFAIK from way back in C and such where properties where just fields, and so if something was a property, either it was constant, or it was real data stored somewhere. With properties, that's really irrelevant because a property becomes simply a function call with no parameters
2
d
So in other words, your suggesting
const val rowCount = 3
Is there even a real benefit here for using const? That's probably what's causing the IDE to think the convention should differ.
m
constants should be in a companion object, or the class itself where it is placed, should be an object rather than a class.
this doesn't mind
we actually disabled coding conventions specifically for this in test classes, because of the whole @Test annotation needing to be inside a class rather than an object.
but other than that, a constant should be inside an object
t
what about constants for @Composable functions? I'm not sure where the high level object would come for those... do you just add an arbitrary one?
m
ONE_WEEK sounds like a constant you would like to use everywhere in your code right? We just use an object per subject, if that makes sense. e.g.
Copy code
object CacheManagerName {
    const val SINGLE_LEVEL_CACHE_MANAGER = "singleLevelCacheManager"
    const val MULTI_LEVEL_CACHE_MANAGER = "multiLevelCacheManager"
}
and (excuse the dutch, but you get the gist)
Copy code
object PatientConstants {
    const val DECLAREERBAAR_BSN = "999999999"
    const val ONDECLAREERBAAR_BSN = "000000000"
    val OVERGANGSPATIENT_PEILDATUM: LocalDate = LocalDate.of(2022, 1, 1)
}