Book Review: Effective Kotlin by Marcin Moskala

Book Review: Effective Kotlin by Marcin Moskala

Introduction

Today, I want to present to you the book "Effective Kotlin" by Marcin Moskala. A friend and former colleague of mine recommended it to me (thank you Patrick). I must admit that I was skeptical after looking at the book before ordering it. Some time ago I stopped reading books that are solely on a "code" level. Programming languages, their compilers or even what is considered best practice (looking at you Scala 2) change so rapidly these days that such books are obsolete a year or two after publication. There are some evergreens of course, e.g., Java Concurrency in Practice, but those are rare in my opinion. "Effective Kotlin" was published in November 2019. According to my definition this means it is already old (for comparison November 2019 Kotlin 1.3.60 was released, today we use Kotlin 1.7.10).

Still, since it was a recommendation, I gave it a try.

The strucuture

The book contains different levels of recommendations. Some cover basics that are not related to Kotlin (e.g., "Design for Readability") and others are very specific details (e.g., "Avoid member extensions"). Additionally, chapters covering general aspects are labeled for better orientation. The book is separated into three parts that center around a certain aspect. Within each part there are several chapters. The chapters within each part get more complicated. This helps when one has to look up some specific advice or searches for a code example.

The content

As already mentioned, the information varies from OOP best practices to very Kotlin specific aspects. Every chapter contains code examples illustrating what is being presented. The examples are easy to understand since they are written in a readable way. I read the printed edition; therefore, the code is well formatted. Some online reviews mention that the formatting is not good when using an e-book reader.

The code is mostly unrelated to a specific platform. From time-to-time specific aspects are pointed out that become relevant when one is not using Kotlin on the JVM. Additionally, some examples show Android code. Nevertheless, one does not need to know the Android platform.

How did the book help me during my daily work?

What I will try sometime soon is to introduce more inline value classes (the ones with the JvmInline annotation and the value keyword). Additionally, what I pay more attention to after having read the book is the usage of sequences when chaining many map, flatMap, filter, etc. transformations.

But the real value is not that I learned this certain pattern or that method, it is more that I have a reference book to check when I get the feeling that there should be a way to write some better code. Each time I get a feeling that there should be a better way I can grab the book and quickly check.

Conclusion

All in all, I have to admit that the book is still relevant these days and that I learned quite a lot. I am not sure if it will become one of those evergreen books, but I would recommend you give it a try.

If Marcin Moskala ever reads this article, here is my recommendation for the next edition: Add an alphabetical index to the end of the book. It would be much easier to search for certain things by looking up a keyword. Actually, that this is missing, is the biggest weakness of the book.

Did you find this article valuable?

Support Code 'n' Roll - Rocking the computer by becoming a sponsor. Any amount is appreciated!