article banner

The second edition of Effective Kotlin: Best Practices is finally ready!

Four years have passed since the release of the book Effective Kotlin: Best Practices. This book was extremely well received by the community, but I always felt that there are a few things that could be improved. It was a stressful thing, because touching a book that is well received is always risky, but I feel with whole my heart that the second edition is better. Not only I updated content to what has changed in Kotlin throughout those 4 years, but I also added a lot of new content and examples. I changed items I feel needed improvement, and I added a couple of new items. Today I am happy to announce that the second edition is ready and released. I finally feel that this book is complete, and I am really proud of it.

What is new in the second edition?

In the second edition, I updated all items, worked on language and added some real-life examples.

I added the following items:

  • Item 2: Eliminate critical sections - the item presenting the essentials of the problem of critical sections and the most important ways to eliminate them on JVM.
  • Item 35: Consider using dependency injection - the item presenting the most important reasons to use dependency injection and how we implement it.
  • Item 48: Consider using object declarations - the item presenting how using object declarations can be a powerful optimization. Parts of this item were extracted from Item 47: Avoid unnecessary object creation.
  • Item 49: Use caching when possible - the item presenting the most important technique for efficiency optimization: caching. Parts of this item were extracted from Item 47: Avoid unnecessary object creation.
  • Item 50: Extract objects that can be reused - the item presents another important techniqiue for efficiency optimization, that is extracting objects that can be reused. Parts of this item were extracted from Item 47: Avoid unnecessary object creation.
  • Item 55: Consider associating elements to a map - the item presents a powerful technique for efficiency optimization, that is associating elements to a map so they can be found in constant time.
  • Item 56: Consider using groupingBy instead of groupBy - the item presents a more efficient alternative to groupBy function for grouping elements.
  • Item 60: Use appropriate collection types - the item presents different collection types that can be used in different situations. It explains how the standard collections work, and then presents alternatives like HashMap, HashSet, Deque, sorted trees.

I also removed some items:

  • Item 4: Do not expose inferred types - this item was merged with Item: Specify the variable type when it is not clear, and together they made Item: Consider making types explicit.
  • Item 8: Handle nulls properly - this item was never a clear suggestion, so I decided to remove it, but the majority of its content was included in other items, like Item 7: Prefer a nullable or Result result type when the lack of a result is possible.
  • Item 21: Use property delegation to extract common property patterns - this item was an explanation of how property delegation works rather than a clear suggestion. Since this topic is well covered in the Advanced Kotlin, I decided to remove it from this book.

Now the book has exactly 60 items, has a similar length as the first edition.

New cover

The second edition has a completely new cover. The main reason for this change is to adjust the style of this cover to the Kotlin for Developers series. Since this version, Effective Kotlin: Best Practices is officially the last book of the Kotlin for Developers series. This does not mean you need to read the previous books first. Each book can be read independently.

The whole series includes:

  • Kotlin Essentials, which covers all the basic Kotlin features.
  • Functional Kotlin, which is dedicated to functional Kotlin features, including function types, lambda expressions, collection processing, DSLs, and scope functions.
  • Kotlin Coroutines: Deep Dive, which covers all the features of Kotlin Coroutines, including how to use and test them, using flow, best practices, and the most common mistakes.
  • Advanced Kotlin, which is dedicated to advanced Kotlin features, including generic variance modifiers, delegation, multiplatform programming, annotation processing, KSP, and compiler plugins.
  • Effective Kotlin: Best Practices, which is about the best practices of Kotlin programming.

Upgrade to the second edition

If you purchased the first edition of the Effective Kotlin book on LeanPub, you can always download the most recent version of the book.

If you purchased the first edition on Amazon, if you Tweet a photo of the book with @ktdotacademy, we will send you a coupon code for the second edition of the ebook on LeanPub. (We do it also for the Kotlin Coroutines book which had its second release in March 2023.)

Where can you find this book?

Effective Kotlin: Best Practices ebook can be found on LeanPub and paperback can be found on Amazon. You can also find an ebook on Amazon, but the price is higher than on LeanPub, due to Amazon rates.

More about the book on this page.