is it bad form to put a companion object at the to...
# announcements
d
is it bad form to put a companion object at the top of a class? I always put them at the bottom but for this file, the top is nice
n
i guess it’s important to be consistent wherever you put it
1
a
The code convention says companion objects last I guess https://kotlinlang.org/docs/reference/coding-conventions.html#class-layout Personally I'm not sure, if the companion object is used as a factory or w/e I think it makes sense to have it first with the ctor etc. But I haven't written a lot of code I wouldn't say be consistent without taking into account what kind of thing it does if that makes any sense
t
We agreed with the team to have it on the top. It is just a decision in the team everyone must hold on to afterwards (either top or bottom, be consistent).
n
i put them at the top because my companion objects tend to be small and that way i can see the superclass of the class and the companion object on a glance and often its just
companion object : KLogging()
h
I also put them at the top
m
The code conventions strongly recommends consistency over all else, and suggests companion object last I, like others, also value consistency over any specific style.