Chapter 9: Idioms and Anti-Patterns

In the previous chapters, we discussed the different aspects of the Kotlin programming language, the benefits of functional programming, and concurrent design patterns.

This chapter discusses the best and worst practices in Kotlin. You'll learn what idiomatic Kotlin code should look like and which patterns to avoid. This chapter contains a collection of best practices spanning those different topics.

In this chapter, we will cover the following topics:

  • Using the scope functions
  • Type checks and casts
  • An alternative to the try-with-resources statement
  • Inline functions
  • Implementing algebraic data types
  • Reified generics
  • Using constants efficiently
  • Constructor overload
  • Dealing with nulls
  • Making asynchronicity ...

Get Kotlin Design Patterns and Best Practices - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.