u/dmcgin r/Kotlin • Recommends
Kotlin Value Classes - Tiny Types to Eschew Errors
[video
And for those of you who like the plain-old-blog-posts
http://oneeyedmen.com/failure-is-not-an-option-part-7.html
#kotlin#valueclasses#tinytypes
4.5K subscribers • 15 videos on Hallway
Intermediate. Assumes working knowledge.
1.4K views4 years ago1 recommendation
Programming languagesSoftware designKotlinDesign patternsRefactoring and legacy code
Duncan McGregor demonstrates how to use Kotlin value classes to create expressive, type-safe tiny types and avoid primitive obsession.
We can usually avoid the errors that result from passing inappropriate arguments to functions, or at least move them from inside the function to outside, where we probably have more context. Kotlin Value Classes (previously known as Inline Classes) are good for this, allowing us to create Tiny Types that are more restricted and expressive than primitives. This is Part 30 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist youtube.com/playlist?list=PL1ssMPpyqociJNwykAOB9_KEZVW7BW7m2 and the code on GitHub github.com/dmcg/gilded-rose-tdd This sub-series on error handling is also a playlist youtube.com/playlist?list=PL1ssMPpyqochiZj41oLAtvht4ScUurHJH You can read more about tiny types and partial functions on my blog oneeyedmen.com/failure-is-not-an-option-part-7.html As far as I can see, Darren Hobbs coined the term Tiny Types darrenhobbs.com/2007/04/11/tiny-types/ If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook java-to-kotlin.dev. Chapter 19 covers error handling.What people say. Recommended as a practical demonstration of using Kotlin value classes to improve type safety.
u/dmcgin r/Kotlin • Recommends
u/dmcgin r/Kotlin • Mentions
On “🤢 Life is too short for working with blank strings.”
u/dmcgin r/Kotlin • Mentions
On “why does invoke operator exist?”