liveBook · Manning

Programming by contract

Programming by contract is a software design technique that specifies component obligations through preconditions, postconditions, and invariants.

How 3 Manning books explain it

Object-Oriented Software Design in C++

Programming by contract is a software design technique that specifies preconditions, postconditions, and invariants for program components and may check them during execution.

How it is used
Uses explicit contracts to prevent surprising behavior in classes, member functions, and subclass hierarchies.
How deep it goes
Explains responsibilities, runtime assertions, a CircularBuffer implementation, and inheritance constraints, but does not provide native C++ contract syntax.
Examples
Demonstrates contracts with CircularBuffer operations and Shipment, Expedited, and International subclasses.
What you can do after
Apply it by documenting and asserting class contracts, checking caller obligations, and evaluating subclass overrides for compatibility.

Read how Object-Oriented Software Design in C++ explains programming by contract →

Software Design for Python Programmers

Programming by contract is a software development technique that specifies component obligations through preconditions, postconditions, and invariants.

How it is used
Uses explicit contracts to prevent surprising runtime behavior in classes and methods.
How deep it goes
Defines three contract elements and demonstrates assertion-based implementation, while deferring native Python support and deployment strategy.
Examples
Demonstrates a CircularBuffer and Shipment subclasses with cost preconditions, day postconditions, assertions, and custom exceptions.
What you can do after
Apply it via Python assertions, predicate methods, and exceptions to specify and enforce critical class behavior.

Read how Software Design for Python Programmers explains programming by contract →

Functional Design and Architecture: Examples in Haskell

A software-design technique that expresses behavioral contracts explicitly and checks implementations against them.

How it is used
Uses explicit contracts to make object-oriented subsystem behavior predictable and implementations accountable.
How deep it goes
Defines explicit contracts and illustrates a violation, but does not detail a specific contract-checking tool or formal notation.
Examples
Uses ILampSwitcher, DaylightLamp, TableLamp, exceptions, global state, absent files, and memory operations as contract cases.
What you can do after
Diagnose implementations that violate client-facing behavioral contracts and recognize why substitutions become unsafe.

Read how Functional Design and Architecture: Examples in Haskell explains programming by contract →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.