https://kotlinlang.org logo
Title
c

Czar

01/18/2018, 1:01 PM
Oooh, forgot about this channel. I have a question about class layout.
companion object
is suggested to be placed at the bottom of the class. This does not make sense to me. CO usually contains constants or stuff like
: KLogging()
so why would anyone want to hide it at the bottom? These constants and
logger
property in case of
KLogging
IMO should be declared at the top so that they be easy to reference "at a glance".
k

kirillrakhman

01/18/2018, 1:02 PM
you mean
companion object
?
c

Czar

01/18/2018, 1:03 PM
of course 😄 I keep mistyping it for some reason 😄
another argument to support my opinion would be constants overuse I've seen them used as configuration in a lot of code bases, keeping them visible would prompt a diligent developer to get rid of them in favor of proper config.
h

hho

01/18/2018, 1:06 PM
I can't find it anymore (free Slack…), but @yole basically said "you don't want to read through all of that whenever you open a class"
c

Czar

01/18/2018, 1:07 PM
that's exactly my argument, there shouldn't be too much of "all of that" in companion object, if there is, it's often just code smell.