liveBook · Manning

Duck typing

Duck typing is a typing approach in which a value’s suitability is determined by the operations or behavior it provides rather than its declared type.

How 3 Manning books explain it

Go in Practice, Second Edition

Duck typing is a typing approach that determines an object's suitability by the methods and behaviors it provides rather than by explicit nominal declarations.

How it is used
Uses method behavior to decide whether independent Go types can satisfy a shared interface.
How deep it goes
Explains interface assignment and compile-time method validation, but does not descend into runtime dispatch internals.
Examples
Uses Animal, Cat, Dog, and Llama types to demonstrate successful interface assignments, compile errors, and method-based repair.
What you can do after
Apply via Go interfaces by designing method signatures and checking type satisfaction through compiler-validated assignments.

Read how Go in Practice, Second Edition explains duck typing →

The Art of Unit Testing 3e

Duck typing is a type-compatibility approach that accepts an object based on the operations it supports rather than its declared type or class.

How it is used
Uses object-parameter injection to replace dependencies with controllable stubs during JavaScript tests.
How deep it goes
Explains matching function signatures, handwritten fakes, runtime checking, and a compile-time interface alternative.
Examples
Uses RealTimeProvider, FakeTimeProvider, PasswordVerifier, getDay(), and a weekend exception test.
What you can do after
Apply it via JavaScript object injection to substitute controllable test dependencies and exercise specific behaviors.

Read how The Art of Unit Testing 3e explains duck typing →

Practices of the Python Pro

Duck typing is a typing approach that determines an object's suitability by the presence of the required behavior rather than by its declared class or type.

How it is used
Enables polymorphism and swappable implementations by relying on required behavior instead of declared classes.
How deep it goes
Explains runtime method checks and shared interfaces, but stops short of formal interface enforcement.
Examples
Uses the duck analogy, FancyTire substitution, and command objects sharing execute.
What you can do after
Apply it via Python by designing consumers around expected methods and attributes rather than concrete classes.

Read how Practices of the Python Pro explains duck typing →

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.