Idioms and Anti-Patterns
In the preceding chapters, we explored various aspects of the Kotlin language, delving into the advantages of functional programming and examining concurrent design patterns.
This chapter focuses on the dos and don’ts in Kotlin programming. It aims to help you recognize idiomatic Kotlin code and understand patterns that are best avoided and serves as a compilation of best practices, covering a range of topics discussed earlier.
You might consider some of the content in this chapter simpler compared to the discussions on concurrent data structures and design patterns from the previous two chapters. However, I believe it’s beneficial to address idioms as a unified topic, and to do so, we needed to complete the entire discussion on coroutines first.
The topics covered in this chapter include:
- Scope functions (and how to utilize them effectively)
- Type checks and casts
- An alternative to the
try-with-resources
statement...