Duck Typing¶
A programming compatibility discipline that accepts a value for the operations it supports rather than requiring declared type ancestry.
Core Idea¶
Duck typing treats a value as compatible with a use because it offers the needed operations or properties, not because its class declares a particular parent. The consumer's requirement, the value's available members and the absence of mandatory nominal ancestry define the pattern. Python's official glossary describes the dynamic style, while accepted PEP 544 calls structural protocol checking “static duck typing.” Checking every value only when an operation is invoked is therefore not universal.[ref-55419005f8eb][ref-33f1058e0360]
Scope of Application¶
PEP 544's Bucket supplies __iter__ without deriving from Iterable, yet collect(Bucket()) passes a static Iterable check. In a different language and task, ECMAScript 2024 Promise resolution retrieves an object's then and treats it as a thenable only if that property is callable; the object need not declare itself a Promise subtype. These are unlike static-iteration and runtime-asynchronous settings for operation-based acceptance.[ref-33f1058e0360][ref-b713560671cc]
Clarity¶
Duck typing is neither “no interface” nor “any matching name is enough.” The required operations form an implicit contract; call shape and behavior matter. A noncallable then is not assimilated, and a socket's recv does not magically satisfy a file-like read contract. It is also distinct from nominal subtyping: explicit inheritance is not the admission criterion.[ref-55419005f8eb][ref-b713560671cc]
Manages Complexity¶
A consumer can rely on a small capability surface rather than enumerate approved concrete classes. Independently written values can qualify without reorganizing a shared inheritance tree. This reduces nominal coupling but can hide semantic mismatches that shape checks alone miss. Static protocols catch some errors earlier; dynamic use can accept cases without prior protocol declarations.[^ref-33f1058e0360]
Abstract Reasoning¶
Start at the consumer: what operation and behavior does it need? Check whether the candidate supplies a compatible member, then ask whether acceptance depends on that member or on declared ancestry. State when and how compatibility is checked. PEP 544's static checker and ECMAScript's runtime Promise algorithm preserve the first three roles while differing on timing, so neither timing is the abstraction's definition.[ref-33f1058e0360][ref-b713560671cc]
Knowledge Transfer¶
The iterable Bucket and callable then example both accept a value by an operation rather than by a common declared class. What does not transfer is the contract itself: iteration is not Promise resolution, and having one method does not guarantee every semantic expectation. The live Structural Type System is a static neighboring discipline, while broader Interface and Substitutability nodes do not supply an uncontested strict parent; the DAG relation is left unparented pending review.[ref-33f1058e0360][ref-b713560671cc]
[^ref-55419005f8eb]: Python Software Foundation, “Glossary: duck-typing”, official Python documentation, duck-typing entry. Direct open returned 503; only the official indexed passage was used. [^ref-33f1058e0360]: Ivan Levkivskyi, Jukka Lehtosalo and Łukasz Langa, PEP 544: “Protocols: Structural subtyping (static duck typing)”, accepted proposal, Abstract and Rationale and Goals. [^ref-b713560671cc]: Ecma International, ECMAScript 2024 Language Specification, §27.2.1.3 and §27.2.2.2, Promise resolving-function and thenable-job steps.
Neighborhood in Abstraction Space¶
Duck Typing sits in a moderately populated region (57th percentile for distinctiveness): it has near-neighbors but no dense thicket of look-alikes.
Family — Controlled Vocabularies & Term Mapping (18 abstractions)
Nearest neighbors
- Proof-Carrying Code — 0.86
- Mass Customization — 0.86
- Portfolio Optimization — 0.85
- Logico-linguistic modeling — 0.85
- Convenience Sampling — 0.85
Computed from structural-signature embeddings · 2026-10-08