Skip to content

Kotlin

What pisses me off about Kotlin is how often I see people trying with all their might not to use standard language features and replace them with their own super-clever solutions instead of just writing something the simplest and most idiomatic. These solutions usually leave a ton of assumptions about what you can and can't do with them. They often have bugs like any other code. They need to be understood in principle. By default we assume that you don't need to understand the language syntax, it's the same on all projects, moreover even in most C-like languages it's the same.

The language itself allows them to do this. Kotlin's ideology has always been complicated, it's a pragmatic general-purpose language (aka write as you want, we don't interfere). We love it for this, of course, we hate it for this. This is misunderstood. There aren't enough recommendations in the documentation from JB, for some reason everyone starts inventing their own bicycles instead of any language construct.

Yes, I'm looking again at those who use a?.let {} instead of if (a != null) {}, for whom a?.let { b } ?: run { c() } is their favorite construct from stdlib, because if/else for them is unreadable code, and this is just right.

BTW scope functions are the most harmful thing in the standard library, convince me otherwise? They have extremely niche use cases, but almost everyone starts abusing them from the day they learn about them.

Or I've seen many times those for whom try/catch or when combined with sealed classes didn't please them somehow and whose code turns into "functional" execute().onSuccess{}.onFailure{}, where forgetting a branch is easy as pie.

Or there are strange guys who write collection.forEach { c -> } instead of for (c in collection) {}. Zero ideas why this extension was even added to the standard library. Good luck doing break/continue/return from a lambda.

And all of this has a common denominator, people for some reason love long one-liner chains. I completely don't understand this. Maybe people think that if they don't see it, then no extra objects are created there, I don't know. In 100% of cases, if we're talking about pure Kotlin, it's better to just create a variable with a telling name, on the next line another one, call some understandable function there, and so on. Combining everything into one construct - don't do it. You complicate life for the compiler, for onboarding newcomers, and for your own work.

What doesn't satisfy people about the language syntax? Why do they do this? Why do you write hellish one-liners with a bunch of limitations? I can't think of any other explanation except that they deduct from your salary for the number of lines or characters.

Do you have this too? What's your favorite thing you remember?