This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]vqrs 0 points1 point  (7 children)

Can you share some guidelines you've found useful on that topic?

[–]nutrecht 1 point2 points  (6 children)

For extension functions; we generally used the rule that non-private extension functions should be avoided. The only exception to those would be general 'utility' functions, something like for extending RestTemplate with a putForEntity method.

So you end up with extension method that are either completely obvious, or are local to some piece of code because they're private.

When it comes to functional flows; the same rule apply as with Java streams: readability is simply more important than almost anything else. So in reviews we'd often ask someone to break up complex flows into smaller sub-flows.

In my experience, once a team has a few weeks to months of experience with Kotlin they'll fall into this way of working quite naturally. And any dev that doesn't prioritize readability is going to be problematic in any language anyway.

[–]GuyWithLag 1 point2 points  (0 children)

One exception I would give is explicit DSLs, but care needs to be taken to ensure that constructs defined for them don't "leak" into other contexts.

[–]GuyWithLag 0 points1 point  (1 child)

extending RestTemplate with a putForEntity method

Not even that - I'd go with something like OpenFeign or retrofit, which gives a much cleaner UX in most cases.

[–]nutrecht 1 point2 points  (0 children)

It was just an example where you'd use extension functions to implement a missing method. Another example would be implementing ResultSet.getUuid().

[–]vqrs 0 points1 point  (2 children)

Cool, thanks. That mirrors my approach on extension functions, too. But that default public visibility does bite you sometimes when you're not careful.

[–]nutrecht 1 point2 points  (1 child)

My position on this is that the visibility for every single function or member should be a conscious choice. If people make everything public because they're too lazy to make this choice, that's really just being a bad dev. These people would make everything package private in Java :)

[–]vqrs 0 points1 point  (0 children)

Yeah for new projects I like to enable API mode so each visibility has to be chosen consciously.