Function Contracts in Practice using C++
summary
Argues that choosing narrow function contracts and checking them (even with C assert) reduces defects, keeps APIs small, and preserves performance; describes a configurable contract-checking system with a replaceable violation handler, two assertion levels (regular vs audit), and a review → assert lifecycle to roll checks into production safely. Shows unit-testing strategy using a throwing handler instead of death tests, gives real examples (optional reference operator, cache watermarks), and ties implementation to Bloomberg practice and ongoing C++ standard work.
AI-written summary · about
chapters (27)
- 0:00Introduction
- 1:26Real-world contract analogy
- 3:31Why contracts matter
- 7:20Feasibility of wide contracts
- 11:14Reliability risks of invalid inputs
- 13:21Maintainability benefits
- 16:11Designing good contracts
- 17:37Minimal versus complete contracts
- 22:34Handling violations
- 25:03Contract checks and UB
- 27:32Side effects in checks
- 30:47Misusing checks for control flow
- 32:13Checks vs input validation
- 32:55Checks and unit testing
- 33:59Summary of contract design
- 35:02Documenting contracts
- 37:54Documentation style comparison
- 45:40Scaling contract checks
- 50:36Custom violation handlers
- 57:00Performance vs checks
- 1:00:14Adding checks to code
- 1:01:38Gradual enforcement review
- 1:05:52Testing contract checks
- 1:08:19Challenges with asserts
- 1:11:11Avoiding noexcept in narrow contracts
- 1:14:43Summary and recommendations
- 1:15:24Q&A
related talks
58mAvoid Misuse of Contracts!
01h 30mContracts, Safety, and the Art of Cat Herding
01h 22mContracts, Safety and Correctness in C++
01h 27mContractual Disappointment in C++
01h 05m“Contract Programming in C++(20) (part 2 of 2)”
57mPerspectives on Contracts for C++
01h 03m“Contract Programming in C++(20) (part 1 of 2)”
01h 21mProgramming with Contracts in C++20
