i feel silly commenting enum classes. how should t...
# random
s
i feel silly commenting enum classes. how should these be commented?
r
Comments? What are they?
s
😄
I usually use @brief and some description.
but this feels superfluous if the names of the enum and its elements are chosen as “self-documenting” identifiers in the first place
o
If it was hard to code, it should be hard to read...
✔️ 1
m
It may feel silly to you because you know its purpose and it’s fresh in your mind. Always put yourself in the shoes of someone reading your code for the first time: what’s the purpose of this enum? What do its constant represent? Try to add a short but meaningful description, even if the names are self-descriptive. Even if the constant have clear names (you’re always biased towards them because they make sense to you), try to think if they need additional explanation for your reader.
Obviously depends on the case, if we’re dealing with
WeekDay.MONDAY
or
Opinion.MAYBE
, of course they’re enough self-descriptive.
s
Well I cannot agree with Ole 🙂 hope this was sarcastic.
yeah I agree Matteo
thanks for giving some confidence
by the way: is there any good resources on metaprogramming in Kotlin? I try to simplify (reduce code duplication) and for this I would need to be able to create classes obeying some interface programatically
m
Thanks, hope you can write better docs with a fresh perspective. As for metaprogramming, I don’t have any resources now, but if you need to implement interfaces at runtime you can use byte buddy, given you’re targeting the JVM. Alternatively you could generate source code to be compiled using KotlinPoet.
s
Yeah Matteo, it’s good to hear a reinforcing opinion
👍 1
okay I’ll check these out
thank you
btw: a colleague approached me and wondered why one would use kotlin. he said it’s mainly used for Android apps
how can I answer this?
m
You can tell him that Kotlin is much more than that: it’s a better Java of some sort, can be used perfectly on the backend (in fact that’s the use I do and how it’s used at my company) wherever you use a JVM. Also Kotlin multi-platform (MPP) can compile for different targets like JS, Android, iOS and native, so you can have an MPP project that has a common module and one or more platform-specific modules that share the common code.
K 1
Anyway, even used just as a replacement for Java it’s a refreshing experience, the syntax is shorter, low boilerplate, has more type safety, including non-nullable types, etc etc. If you search the web or Medium is full of articles explaining why Kotlin is a great language choice.
K 1
I was looking for this blog among my favourites but couldn’t find it at the time of this thread. It’s a very good and deep series on Documentation an comments: https://nipafx.dev/#tags~~documentation A recommended reading to clear your initial doubts!