Strings are Evil: Methods to hide the use of primitive types
summary
Primitive primitives like Int and String cause bugs by allowing invalid domain values; concrete remedies shown include a simple type alias, a case class with a sealed abstract case class wrapper and private constructor to prevent invalid copies, the external library refined which checks literals at compile time and returns Either at runtime for dynamic input, and the upcoming opaque types (SIP) that promise zero runtime overhead; examples include UUIDs validated to 32 hex digits and nonempty strings, and tradeoffs are measured (compile-time checks vs runtime Either and adoption complexity).
AI-written summary · about
chapters (10)
- 0:00Start
- 0:29Outline
- 4:49Time Zones
- 11:04Runtime Overhead
- 11:58Make the Constructor Private
- 13:52Sealed Abstract Case Class Uid
- 16:34Functions
- 25:36Opaque Types
- 28:08Summary
- 29:46Refinement Types
related talks
14mWe must talk about String
40mBugs?! Where do they come from?
01h 02mBasics Designs and How We Got Them Wrong
50mCracking the Code to Secure Software
37mOvercoming Our Primitive Obsessions
28mThe Fellowship of the String
25mImmutable APIs and mutable internals: a Scala design case study
55m“Using Types Effectively"
