liveBook · Manning

Defensive programming

Defensive programming is a technique that anticipates invalid inputs, failures, misuse, and unsafe states and explicitly guards against their harmful effects.

How 2 Manning books explain it

Object-Oriented Software Design in C++

A programming technique that validates inputs and guards against invalid states or programming errors.

How it is used
Guards object construction and search operations against programming errors in a book-catalogue design.
How deep it goes
Explains runtime parameter checks through a variant-backed map and constructor assertions, while deferring broader checking in short examples.
Examples
Uses typed book attributes, constructor assertions, catalogue searches, and partial queries such as genre and author.
What you can do after
Apply runtime validation to construct only proper objects from parameter values.

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

Software Design for Python Programmers

Defensive programming is a technique that validates inputs and guards against programming errors to preserve valid program states.

How it is used
Uses runtime checks to prevent invalid objects and guard application state against programming errors.
How deep it goes
Shows constructor assertions and matching behavior, while noting that broader examples generally omit parameter checks.
Examples
Uses typed book attributes, invalid-value prevention, case-insensitive author matching, and partial catalogue searches.
What you can do after
Build valid Python domain objects and diagnose invalid parameter values before they enter the application.

Read how Software Design for Python Programmers explains defensive programming →

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.