Kotlin is a powerful and pragmatic language, but it's not enough to know about its features. We also need to know when they should be used and in what way. This book is a guide for Kotlin developers on how to become excellent Kotlin developers. It presents and explains in-depth the best practices for Kotlin development. Each item is presented as a clear rule of thumb, supported by detailed explanations and practical examples.
Effective Kotlin provides insights into the idiomatic way of Kotlin development, as well as many general programming best practices and details about advanced Kotlin features like DSL creation, generics, platform types or inline functions and classes. All that for experienced Kotlin developers to get more effective when they use this programming language: to make safe, well designed and efficient code.
To really unleash the advantages of Kotlin, we need to use it properly. To do so, not only do we need to know about different Standard Library (stdlib) functions but even more, we need a good understanding of Kotlin features, purpose, and design. The main goal of this book is to explain how to use different Kotlin features to achieve safe, readable, scalable, and efficient code. Since this book is written to help developers get better at writing code, it also touches many general rules for programmers. This book tries to compose as much knowledge about best practices in Kotlin as possible. You can call it a collection of best practices.
This book is not teaching basics. It assumes that you have enough knowledge and skills to do Kotlin development. If you don’t, I recommend starting first from resource designed for beginners.
Effective Kotlin is directed to experienced Kotlin developers. Though I will assume that even experienced developers might not know some features. This is why I explain some concepts like:
I want this book to be a complete guide for Kotlin developers on how to become an amazing Kotlin developer.
Concepts in the book are grouped into three parts. Each part is divided into chapters, which are subdivided into item. Those parts are:
More general rules about making good quality code. This part is for every Kotlin developer, no matter how big their project is. It starts from items about safety and later talks about readability. It is not a coincidence that the first chapter is dedicated to safety. I believe that program correctness generally is of the highest priority, and safety is an important component. Readability is another item because the code is not only for a compiler but also for programmers. Even when we work alone, we want code that is readable and self-explanatory.
This section is for developers creating a project together with other developers, or creating libraries. It is about conventions and setting contracts. It will, in the end, reflect on readability and safety, but all in terms of correct code design. This part is a bit more abstract at the beginning, but thanks to that it can explore topics that are often omitted in books about code quality. This section is also about preparing our code for growth. A lot of items are about being ready for changes in the future. Therefore it is an especially important section for developers creating large projects.
This section is for developers that care about code efficiency. Most of the rules presented here do not come at the cost of development time or readability, so they are suitable for everyone. However, they are particularly important for developers implementing high-performance applications, libraries, or applications for millions.
Introduction: Be pragmatic
Marcin Moskala is an experienced developer and Kotlin trainer. He is the founder of the Kt. Academy, an official JetBrains partner for Kotlin training, author of the books Effective Kotlin, Kotlin Coroutines, Functional Kotlin and Android Development with Kotlin. He is also the main author of the biggest medium publication about Kotlin and a speaker invited to many programming conferences.
25 April 2021
We start a process of updating the book, and sharing some chapters online as public articles.
14 October 2019
Generics are important for effective Kotlin development, and yet many experienced developers have trouble using them. That's is why we just introduced three new items dedicated to generics in Kotlin:
Item 22: Use generics when implementing common algorithms Item 23: Avoid shadowing type parameters Item 24: Consider variance for generic types
26 August 2019
The book is finally published! It took a lot of time and energy, but Effective Kotlin is finally available in e-book.
26 July 2019
Alpha testing started today - reviewers are reading the beta version of the book and giving final suggestions. It means that Effective Kotlin should be published within two months.