Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types That Enforce

This segment should take about 45 minutes. It contains:

SlideDuration
Newtypes: Parse, Don’t Validate12 minutes
Enums: Illegal States, Unrepresentable12 minutes
Typestate: State Machines That Compile12 minutes
RAII, Guards, and Drop Bombs9 minutes

Four patterns with one purpose: move a runtime check into the type system, so generated code doesn’t need to remember to perform it.

For a reviewer, these patterns are also a signal. Their presence suggests the codebase was designed. Their absence, with validation scattered through bodies and states tracked in booleans, suggests it accumulated.