I guess many of us love Elvis, both the artist and the operator in Kotlin. But it can lead to some hidden pitfalls if you are not aware of how it works.

Image for post
Image for post

I only realized recently when Vladimir Zdravkovic put some code on twitter and ask us to guess what it’s printing:

Image for post
Image for post

I assumed a hidden puzzle but I could not see the issue. …

Image for post
Image for post

Writing your classes with a good API is hard but important. As the writer is trying to make it easy for the user, we sometimes tend to repeat ourselves by adding convenient methods.

Think about the List interface in Java. To check if there are no elements in the list we could check list.getLength() == 0 or we simply ask for isEmpty().

The 2nd one reads much better. But it also adds a duplication and implicit connection between the two: If the list is empty, it can’t contain any elements! This must be respected by every implementer of the interface!

We can easily think of many other methods with implicit dependencies. …

How tools made us forget how to write sane constructors

Image for post
Image for post

In an ideal world, developers get smarter every day. The code we write this year should be better than the code we wrote 10 years ago, which in turn should be better than the code 20 years ago. Today we have better tools, more modern languages, and better practices.

But as often in life, we realize we are not living in that ideal world. …


Danny Preussler

Android @ Soundcloud, Google Developer Expert, Conference Nomad, Geek, Goth, Cyborg, Ex @Viacom @Groupon @eBay ♡ Kotlin ♡ TDD ♡ Clean Code

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store