About the Book
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.
If you are interested in paperback, you can purchase it here.
Bundles that include this book
Well done! I've read a few items and I have to admit that I learned some interesting stuff. Great book :)
Really love this book! ?
Some time ago I started reading @EffectiveKotlin by @marcinmoskala, it's a must-read for every developer writing Kotlin. Even if you don't agree with all the items, for sure it will make you think twice about what you're coding.
Thanks for writing Effective Kotlin, I'm liking the tips from the book so far.
I really enjoyed your Effective Kotlin book and intend to use it for an "Advanced Kotlin" workshop series I'm planning at work
Table of Contents
- Introduction: Be pragmatic
- Part 1: Good code
Chapter 1: Safety
- Item 1: Limit mutability
- Item 2: Minimize the scope of variables
- Item 3: Eliminate platform types as soon as possible
- Item 4: Do not expose inferred types
- Item 5: Specify your expectations for arguments and states
- Item 6: Prefer standard errors to custom ones
Item 7: Prefer a nullable or
Resultresult type when the lack of a result is possible
- Item 8: Handle nulls properly
Item 9: Close resources with
- Item 10: Write unit tests
Chapter 2: Readability
- Item 11: Design for readability
- Item 12: An operator’s meaning should be consistent with its function name
- Item 13: Use operators to increase readability
- Item 14: Specify the variable type when it is not clear
- Item 15: Consider referencing receivers explicitly
- Item 16: Properties should represent a state, not a behavior
- Item 17: Consider naming arguments
- Item 18: Respect coding conventions
- Part 2: Code design
Chapter 3: Reusability
- Item 19: Do not repeat knowledge
- Item 20: Do not repeat common algorithms
- Item 21: Use property delegation to extract common property patterns
- Item 22: Use generics when implementing common algorithms
- Item 23: Avoid shadowing type parameters
- Item 24: Consider variance for generic types
- Item 25: Reuse between different platforms by extracting common modules
Chapter 4: Abstraction design
- Item 26: Each function should be written in terms of a single level of abstraction
- Item 27: Use abstraction to protect code against changes
- Item 28: Specify API stability
- Item 29: Consider wrapping external APIs
- Item 30: Minimize elements’ visibility
- Item 31: Define contracts with documentation
- Item 32: Respect abstraction contracts
Chapter 5: Object creation
- Item 33: Consider factory functions instead of secondary constructors
- Item 34: Consider a primary constructor with named optional arguments
- Item 35: Consider defining a DSL for complex object creation
Chapter 6: Class design
- Item 36: Prefer composition over inheritance
- Item 37: Use the data modifier to represent a bundle of data
- Item 38: Use function types or functional interfaces to pass operations and actions
- Item 39: Use sealed classes and interfaces to express restricted hierarchies
- Item 40: Prefer class hierarchies instead of tagged classes
- Item 41: Use enum to represent a list of values
Item 42: Respect the contract of
Item 43: Respect the contract of
Item 44: Respect the contract of
- Item 45: Consider extracting non-essential parts of your API into extensions
- Item 46: Avoid member extensions
- Part 3: Efficiency
Chapter 7: Make it cheap
- Item 47: Avoid unnecessary object creation
- Item 48: Use the inline modifier for functions with parameters of functional types
- Item 49: Consider using inline value classes
- Item 50: Eliminate obsolete object references
Chapter 8: Efficient collection processing
- Item 51: Prefer Sequences for big collections with more than one processing step
- Item 52: Consider associating elements to a map
- Item 53: Consider using groupingBy instead of groupBy
- Item 54: Limit the number of operations
- Item 55: Consider Arrays with primitives for performance-critical processing
- Item 56: Consider using mutable collections
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 million USDwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them