“Using Types Effectively"
summary
Argues that C++ features like std::optional (optional<char> has 257 values) and std::variant (char|bool has 258 values) let types express exact state so illegal states become compile errors. Shows refactors: enum+fields → variant of per-state structs for connections, optional for nullable alias, and a phantom-type FormData<Dirty/Clean> that forces calling sanitize to avoid SQL injection. Uses cardinality arithmetic (products, sums, exponentials) and promotes writing total functions and typedriven development to reduce bugs and tests.
AI-written summary · about
chapters (25)
- 0:00Introduction to types
- 1:03Types as sets of values
- 3:09Type cardinality game
- 8:10Product and sum types
- 13:18Algebra of data types
- 15:26Modeling state with variants
- 17:53Nullable fields and optionals
- 18:55Monster AI state modeling
- 21:41Types and design patterns
- 23:10Designing with types
- 24:15Phantom types for behavior
- 27:25Total functions game
- 36:35Self-documenting code
- 38:20Types vs testing
- 39:48Algebra with data types
- 43:22Goals for well-typed code
- 44:13Q&A: Partial vs total functions
- 45:41Q&A: Lambda injection
- 46:23Q&A: Optional and sentinels
- 47:11Q&A: Error handling with variants
- 48:57Q&A: Performance trade-offs
- 49:22Q&A: Optional and pointers
- 51:58Q&A: Business logic changes
- 52:41Q&A: Function type math
- 55:16Closing remarks
related talks
41m“Avoiding Disasters with Strongly Typed C++”
01h 00m“Enhanced Support for Value Semantics in C++17”
01h 04m“Sane and Safe C++ Classes”
01h 20mWhat Classes We Design and How
57mSane and Safe C++ Class Types
46mC++: No more nulls! (Fixing the billion dollar mistake)
58mOO Considered Harmful
01h 01mEasy to Use, Hard to Misuse: Declarative Style in C++
