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
nfrankel
01/23/2019, 5:47 AM
i guess it’s important to be consistent
wherever you put it
➕ 1
a
Alowaniak
01/23/2019, 7:08 AM
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
Tom Adam
01/23/2019, 7:38 AM
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
Nikky
01/23/2019, 8:01 AM
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
hudsonb
01/23/2019, 1:19 PM
I also put them at the top
m
Mike
01/23/2019, 4:04 PM
The code conventions strongly recommends consistency over all else, and suggests companion object last
I, like others, also value consistency over any specific style.