Easy to Use, Hard to Misuse: Declarative Style in C++
summary
Argues that fewer statements and more expressions make C++ code easier to reason about, showing concrete rewrites: replace assignment-in-conditions with if-initializer, use an immediately-invoked lambda or optional-like monadic access for weak_ptr locking, and prefer RAII and std helpers (std::exchange, apply, no_discard) to catch misuse. Demoed a reusable schedule/backoff builder used in real projects, a logging “sync” interface returning bool, and a template bitmask type-state trick that enforces required fields at compile time; found zero chained-assignment uses in a 100k+ line codebase.
AI-written summary · about
chapters (34)
- 0:00Intro
- 0:19Overview
- 1:48Indicators of declarative style
- 6:54History of assignment
- 13:50Declarative style example
- 16:20Not an expression statement
- 19:02What can we say
- 19:53Core guidelines
- 21:00Other things
- 23:59Algorithms
- 25:32ObjectOriented Style
- 28:07Log Sync
- 31:48Declarative Style
- 32:51Compositional Patterns
- 33:11ObjectOriented Patterns
- 34:19Builder Pattern
- 35:20Builder Pattern Example
- 39:55Send Request Example
- 40:38Fluent Style
- 42:05Functions Lambdas
- 42:39Overloads
- 45:01operator overloading
- 45:33imperative safety gear
- 46:00no discard
- 48:17identity
- 49:00guidelines
- 51:48conditional replacement metapattern
- 53:30goal of replacing
- 54:07point of use
- 54:37safety gear
- 55:06clarity of interfaces
- 56:12goals for clarity
- 57:04passing fields in constructor
- 58:01identifying monoids
related talks
54mWriting C++ to Be Read
01h 22mSimplicity: not just for beginners
45mPostmodern Programming
01h 18mAbstraction: The True Superpower of C++
51mC++ ...Easy, Elegant, Powerful!
32mCute C++ Tricks, Part 2 of N: More code you should learn from and never write
01h 01mSome Programming Myths Revisited
01h 28mModern C++ Design reloaded
