Is 'Effective Kotlin' Effective?

8 October 2019

‘Effective Kotlin' follows in the long line of renowned Effective programming books. But is it a worthy addition to the series?’

The Legacy of Effective C++

It's good form when beginning a review to declare your own bias, and in my case there is plenty. Back in the mid 90’s, when I was a recent graduate and neophyte C++ developer, Effective C++ saved my bacon. The combination of relevant content, accessible writing style and pithy content helped convince me I hadn’t chosen the wrong profession and kept me hacking away at C++ till the language made sense. So any book that lays claim to this noble tradition is always going to be held to a higher standard in my eyes. When you walk on sacred ground you better have washed your feet.

The Negative Aspects of Effective Kotlin

In that regard, I found this book sorely lacking. The essence of the problem comes in the introduction where the author states the book will differ from the traditional format because “in contrast to Java, Kotlin is not worried about deprecating something and fixing it in the future”. This is to miss the point of the format entirely. Books in the ‘Effective N’ tradition do not exclusively focus on workarounds to deprecated features, but instead document the idioms within the language that intermediate developers find confusing or non-intuitive.

Any language which mixes multiple programming styles (imperative, OO, FP etc…) is going to face difficult trade-offs that result in unique idioms. This is why Effective C++, Effective Modern C++, Effective Python and Effective C# are such valuable resources. This goes double for a language like Kotlin, which has to balance providing a ‘clean start’ with running atop a well weathered VM, and offering an accessible, ‘script-like’ syntax with generating efficient bytecode.

As such, there is a lot of scope in Kotlin for writing a traditional Effective style book. For example I would have expected items such as:

  • Know when to use the standard utility functions
  • Understand how properties affect inheritance
  • Manage Co and Contra-Variance with ‘in’ and ‘out’

Instead large sections of the book are devoted to general coding advice, already exhaustively covered in OO textbooks. It’s hard to see what place topics like the following have in a specialist Kotlin text:

  • Prefer composition over inheritance
  • Do not repeat knowledge
  • Avoid unnecessary object creation
  • Prefer standard errors to custom ones

It's also hard to pin down precisely what level of Kotlin knowledge the author expects. For example the @DSLMarker annotation is covered in depth in Chapter 2 but DSL’s are not covered as a topic till Chapter 5. The format of the book seems to more closely resemble lecture notes from a ‘Kotlin for Java coders’ course that veered off tangent and ended up exploring more general areas.

The Positive Aspects

If we disregard the non Kotlin specific sections of the book and the self-confessed betrayal of the format then the remaining material is quite good. Important topics for the intermediate Kotlin developer are introduced. These include property delegation, data classes, copy methods, resource management and the proper use of collections. At times however the discussion seems to revert to a tutorial on the core language, for example the item on eliminating platform types spends its time explaining what these types are, as opposed to expounding on strategies for removing them.

Summary

If you are a relatively new Kotlin developer, still making the transition over from Java, then this book is worth a read. But there are several books that should be much further up your reading list. As a worthy entry in the ‘Effective’ series of books I have to say that this title misses the mark completely, mostly by not aiming for it in the first place.

Article By
blog author

Garth Gilmour

Head of Learning