Fact-checked by Grok 2 weeks ago

Duck typing

Duck typing is a programming concept in dynamically typed languages, where the suitability of an object for a given is determined solely by whether it possesses the required methods and attributes at , rather than by its declared type or . This approach embodies the principle encapsulated in the adage: "If it walks like a duck and quacks like a duck, then it must be a duck," allowing code to treat any compatible object as equivalent without explicit type checks. The term "duck typing" was coined by Python contributor Alex Martelli in a July 2000 message to the comp.lang.python , highlighting 's reliance on behavioral compatibility over nominal typing. Primarily associated with , the paradigm is also central to other dynamic languages like and , where it facilitates structural polymorphism—enabling objects from unrelated classes to be used interchangeably if they support the same . In contrast to statically typed systems like , which enforce type compatibility at through explicit declarations or , duck typing defers checks to runtime, raising exceptions only if a method is missing when invoked. This style promotes code flexibility, , and reusability by focusing on behavior rather than implementation details, though it can lead to subtler errors in large codebases. Python's official documentation underscores this tradition, noting that code typically assumes objects will respond appropriately to method calls without prior type verification. Over time, extensions like Python's typing protocols have blended duck typing with optional static hints, enhancing while preserving dynamic essence.

Fundamentals

Definition

Duck typing is a programming paradigm employed in dynamic languages, where an object's suitability for an operation is assessed at runtime based solely on the presence of necessary methods and attributes, irrespective of its class or explicit type declaration. This approach contrasts with traditional type systems by prioritizing behavioral compatibility over nominal or structural type checks, allowing objects to be used interchangeably if they exhibit the required interface. The core principle of duck typing is encapsulated in the adage: "If it walks like a and quacks like a , then it must be a ," adapted to software to emphasize that an object's effective type is defined by its observable behaviors rather than its declared identity. In practice, this means code attempts to invoke methods or access attributes, succeeding if they exist and failing with an exception otherwise, often using techniques like hasattr() checks or "Easier to Ask for Forgiveness than Permission" (EAFP) error handling. Duck typing differs from , where programmers explicitly declare variable types in the source code for compile-time verification, such as in languages like or C++. It also contrasts with latent typing, which involves implicit types that are inferred and checked without explicit declarations, typically at in statically typed languages like . Instead, duck typing defers all type resolution to runtime, enabling flexible but potentially error-prone polymorphism. A key characteristic of duck typing is its facilitation of polymorphism through shared behavior alone, eliminating the requirement for hierarchies or explicit interfaces to establish between objects. This behavioral polymorphism promotes code reusability and decoupling, as functions can operate on any object providing the expected methods, without enforcing a common superclass.

Origin and History

The concept of duck typing originates from the colloquial saying "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck," a form of informal reasoning traced back to at least the early and popularized in various contexts by . The term "duck typing" was coined in the programming domain by Dave Thomas, a prominent Ruby developer and co-author of Programming Ruby, to describe a style of dynamic typing where object compatibility is determined by behavior rather than explicit type declarations; it first appeared in discussions around 2000 and in the second edition of the book in 2005. In the Python community, the idea gained traction shortly thereafter through Alex Martelli, who applied the duck analogy in a July 26, 2000, post on the comp.lang.python mailing list, emphasizing behavioral checks over type inspections: "don’t check whether it IS-a duck: check whether it QUACKS-like-a duck, WALKS-like-a duck, etc." This marked an early adoption around 2001, with Martelli further popularizing it via talks and writings that highlighted its advantages in flexible code design. The concept evolved rapidly, spreading to other dynamic languages such as —where it became integral to the language's philosophy—and by the mid-2000s, enabling polymorphic behavior without rigid interfaces. By 2009, it influenced the of Go, which adopted structural typing for interfaces, allowing implicit satisfaction based on method signatures akin to duck typing principles. Key milestones include its formal acknowledgment in 's ecosystem around 2003, as reflected in community resources and the growing literature on dynamic languages, followed by broader academic exploration in post-2010 papers analyzing and polymorphism in languages like and .

Core Concepts

Behavioral Compatibility

Behavioral compatibility in duck typing is established through the "duck test," a principle where an object's suitability for a particular role is determined by its ability to exhibit the required behaviors—such as responding to specific method calls or attribute accesses—rather than by its explicit type declaration. If an object walks like a duck, swims like a duck, and quacks like a duck, it is treated as a duck for the purposes of the code, regardless of its actual class or inheritance hierarchy. This approach, originating from the colloquial duck test attributed to poet James Whitcomb Riley in the late 19th century and adapted to programming, prioritizes runtime verification over static type checks. The core mechanism involves attempting to invoke the expected methods or access attributes directly; successful execution confirms compatibility, enabling seamless integration without prior type assertions. This facilitates ad-hoc polymorphism, a form of polymorphism where unrelated classes can be substituted interchangeably as long as they implicitly implement the same behavioral , promoting flexible and code structures. For instance, in a designed to process any object that quack() , instances of diverse classes—such as Duck or RubberDuck—are compatible solely if they provide that method, allowing the function to operate polymorphically without knowledge of the object's concrete type. If an object's behaviors do not match the expectations, compatibility fails at , typically raising exceptions like AttributeError for missing attributes or methods, which must be handled explicitly by the . This error-handling , often aligned with the "Easier to Ask for Forgiveness than Permission" (EAFP) style, underscores the dynamic nature of duck typing, where mismatches are detected and resolved during execution rather than at . Such evaluation ensures that only objects demonstrating the precise behavioral requirements are deemed , maintaining the integrity of polymorphic interactions.

Runtime Behavior Verification

In duck typing, an object's suitability is verified at through attempts to use its s and attributes, without requiring static type declarations or annotations. The dynamically checks whether an object supports the expected behaviors—such as responding to specific calls—only when those operations are attempted, embodying that "if it walks like a and quacks like a , then it is a ." This process enables objects of diverse classes to be treated interchangeably as long as they exhibit compatible behaviors during execution. These checks typically occur upon the first invocation of the relevant code path, facilitating late binding where the exact type need not be known in advance. By deferring validation to , duck typing supports flexible polymorphism, allowing code to adapt to varying object types without compile-time constraints. This mechanism aligns with practices in languages like , where optional type hints via protocols can be introduced to enhance static analysis while preserving dynamic behavior. A key advantage of this approach lies in its support for agile refactoring; modifications to object interfaces propagate naturally through behavioral usage rather than rigid type hierarchies, reducing the overhead of updating declarations across large codebases. Nonetheless, the absence of early detection means incompatibilities may surface only during execution, potentially leading to exceptions that are harder to diagnose than compile-time errors. To address these pitfalls, comprehensive is essential for proactively validating behavioral compatibility before deployment.

Usage in Programming Languages

In Dynamic Languages

Duck typing is a core feature of dynamically typed languages, where type compatibility is determined by the presence of required s or properties at rather than explicit declarations. In these languages, objects are interchangeable if they exhibit the expected behavior, enabling flexible and concise code without rigid type hierarchies. This approach contrasts with static typing by deferring type checks until invocation, often resulting in errors if behaviors mismatch, but promoting polymorphism through behavioral conformance. In , duck typing is natively supported through the object's dynamic attribute lookup and special method . For instance, the built-in len() function works with any object that implements the __len__() special method, returning an representing the object's length, without requiring from a specific base class. This allows custom classes, such as a simple counter, to be treated as sequences simply by defining __len__(); for example, len(MySequence()) succeeds if __len__() is present, embodying the principle that "if it quacks like a duck, it's a duck." 's iterable similarly relies on duck typing: an object is iterable if it defines __iter__() returning an with __next__(), enabling it to work seamlessly with for loops and functions like list(). Ruby exemplifies duck typing through implicit interfaces and method existence checks, allowing modules like Enumerable to extend functionality based on behavioral requirements. The Enumerable module provides methods such as map, select, and reduce but requires the including to implement an each method that yields successive elements; once included, these methods become available without further specification. For example, a custom collection gains iteration capabilities by defining each and mixing in Enumerable, demonstrating how Ruby prioritizes method support over type identity for protocol conformance. This pattern extends to , where defining methods like + enables arithmetic-like behavior on non-numeric objects. JavaScript, with its prototype-based inheritance, employs duck typing via property and method checks, particularly for array-like objects. Functions like Array.from() accept any "array-like" object—defined as one with a non-negative integer length property and indexed access via numeric keys from 0 to length-1—converting it to a true array without requiring the Array prototype. This enables non-array objects, such as the arguments object in functions or NodeList from DOM queries, to be iterated with methods like forEach() if they possess the necessary properties, as the runtime inspects behavior rather than type. Iterable protocols in JavaScript further support duck typing through the @@iterator symbol, allowing custom objects to integrate with for...of loops by implementing a method that returns an iterator. Common patterns across these languages include and iterable protocols, where behavioral conformance unlocks interoperability. In and , special or conventional methods (e.g., __add__ or +) allow objects to participate in operations like if implemented, while uses property presence for similar effects. These mechanisms foster modular code by relying on runtime method resolution, as seen in iterable handling where defining iteration methods grants access to looping constructs without explicit type annotations.

In Static Languages

Statically typed languages enforce type checks at , which inherently conflicts with pure duck typing's reliance on behavior verification, as any type mismatches are caught early rather than deferred to execution. This compile-time rigidity prevents seamless without explicit type declarations, often requiring developers to anticipate and specify interfaces or upfront to avoid errors. Workarounds emerge through structural and systems that approximate duck typing by focusing on presence rather than nominal . In Go, structural typing via enables duck typing-like behavior at , where a type implicitly satisfies an interface if it implements all required methods, without needing explicit conformance statements. For instance, the empty interface interface{} acts as a generic container similar to dynamic languages' any type, but runtime type assertions—such as i.(T)—are used to safely extract and verify underlying types, mimicking duck typing's behavioral checks post-compilation. This hybrid approach balances static safety with flexibility, though it introduces potential panics if assertions fail. Rust's traits provide a compile-time akin to duck typing by defining shared behaviors that types can implement by providing the required methods through explicit declarations, allowing polymorphic code without runtime overhead in many cases. objects enable for unsized types, producing code structurally similar to duck typing while leveraging the to eliminate runtime type checks, thus ensuring safety without the error-proneness of pure dynamic approaches. C++ employs techniques like Substitution Failure Is Not an Error (SFINAE) to enable compile-time "duck typing" by selecting template overloads based on whether a type possesses specific member functions or types, effectively checking behavior during instantiation without runtime intervention. This allows generic code to adapt to types that "quack like a duck" structurally, though it demands intricate declarations and can lead to complex error messages. adopts structural typing as a compile-time of duck typing, where is determined by —matching properties and methods—rather than names, permitting flexible function arguments as long as they conform structurally. However, since compiles to dynamic , runtime fallbacks are necessary for actual behavior verification, bridging static analysis with dynamic execution. Post-2010 language evolutions, such as Swift's introduction in 2014, incorporate protocol extensions to enhance behavioral flexibility in static contexts; these allow default implementations for protocol requirements, enabling types to conform with minimal custom code while still enforcing compile-time checks on method availability. This feature promotes protocol-oriented programming, approximating duck typing's adaptability without sacrificing type safety.

Comparisons to Other Systems

Structural Typing

Structural typing is a in which type compatibility and equivalence are determined by the structure of types—specifically, the presence, names, and types of their members such as methods and fields—rather than by explicit names, declarations, or relationships. This enables two types to be considered interchangeable if they share the same relevant structural components, fostering polymorphism based on observable behavior without requiring nominal type annotations or class hierarchies. A key distinction from duck typing lies in the timing of enforcement: structural typing verifies structural compatibility at compile-time within static type systems, providing early error detection, whereas duck typing defers such checks to in dynamic languages, potentially leading to exceptions if structures mismatch during execution. For instance, in , an object type is compatible with an if it includes all required members with matching signatures, allowing implicit conformance without explicit declarations. In , object types support width and depth structurally, where an object with additional methods is a subtype of one with a , and compatibility recurses through method return types. These mechanisms ensure compile-time guarantees of behavioral fit, contrasting duck typing's reliance on method resolution. Despite these differences, structural typing and duck typing overlap significantly in promoting behavior-based compatibility over name-based declarations, both enabling ad-hoc polymorphism akin to interfaces without inheritance. This shared foundation allows code to work with any type exhibiting the necessary structure or behavior, as seen in Rust's impl , which supports structural-ish generics by abstracting over types that implement specific traits, blending nominal trait bounds with implicit structural matching. Such parallels position duck typing as a dynamic analog to structural typing, extending its principles to environments lacking static . Structural typing predates duck typing, with foundational implementations in languages like OCaml's object from the mid-1990s influencing the of flexible, structure-oriented in subsequent dynamic languages. This historical precedence provided a conceptual blueprint for duck typing's emphasis on behavioral checks, adapting static structural to interpretive contexts.

Nominal Typing

Nominal typing is a where type compatibility is determined by explicit names and declared relationships between types, rather than by their internal structure or behavior. In such systems, two types are considered compatible or subtypes only if they share the same nominal identifier or if a explicit subtype declaration exists, such as through hierarchies or implementations. This approach contrasts sharply with duck typing, which disregards type names and focuses instead on whether an object exhibits the required behaviors at . Languages like and C# exemplify nominal typing, where a must explicitly conformance to an using the implements clause to be treated as compatible with that . For instance, to use a custom in Java's algorithms, it must implement the Comparable interface and provide a compareTo ; mere possession of a similar without the declaration results in a compile-time error. In contrast, duck typing in dynamic languages like allows any object with a compareTo-like to participate in without formal declarations, prioritizing behavioral compatibility over nominal ones. This formal requirement in nominal systems enforces stricter contracts but reduces flexibility, as unrelated types cannot be interchanged even if they share identical behaviors. The implications of nominal typing include enhanced compile-time safety, as the compiler verifies explicit relationships to prevent type mismatches before , thereby reducing errors in large-scale . However, this rigidity can lead to , such as repeated implementations across similar classes, limiting compared to duck typing's implicit adaptability. Nominal typing's emphasis on declared helps maintain clear semantic boundaries in applications, where unintended type usages could introduce subtle bugs. Historically, nominal typing dominated statically typed object-oriented languages in the pre-2000s era, powering enterprise staples like C++ and early , which prioritized robust type hierarchies for scalable systems. The rise of duck typing in dynamic languages influenced subsequent hybrids; for example, Kotlin retains nominal but incorporates extension functions to add behaviors to existing types without modifying their declarations, blending explicit safety with greater expressiveness.

Protocols and Interfaces

Protocols and interfaces represent formal mechanisms in programming languages that define named specifying the methods and properties required for an object to exhibit certain behaviors, thereby enabling behavioral compatibility without relying solely on . In , an is a reference type that declares a set of methods, which implementing classes must provide implementations for, ensuring explicit adherence to the at . Similarly, Python's , introduced in version 3.5 and expanded thereafter, includes classes that allow developers to define structural requirements for types, facilitating static analysis of duck-like compatibility without enforcing runtime . These constructs provide a blueprint for expected behaviors, such as requiring a quack() method for duck-like objects, but mandate explicit conformance declarations. In contrast to pure duck typing, which determines compatibility purely at based on the presence of when invoked—without any predefined contracts—protocols and interfaces add layers of , self-documenting intent, and optional static type checking to catch mismatches early. For instance, duck typing in pre-3.8 versions allowed any object with a read() to be used as a file-like object at , but offered no compile-time verification or named specification, potentially leading to subtler errors. Protocols bridge this gap by enabling "static duck typing," where type checkers like mypy can verify structural conformance without nominal inheritance, yet execution remains dynamically flexible as in traditional duck typing. Examples illustrate these distinctions clearly. Swift's protocols support default implementations for methods, permitting types to conform partially by overriding only what's necessary, which enhances reusability while providing compile-time guarantees absent in pure duck typing; for example, a Drawable protocol might define a default draw(in:) method that conforming types like Circle or Rectangle can extend. In contrast, Haskell's typeclasses act as a compile-time analog to duck typing, defining behavioral requirements (e.g., the Eq class mandating an == operator) and resolving instances during compilation for ad-hoc polymorphism, ensuring without runtime dispatch overhead typical of dynamic duck typing. Post-2015, dynamic languages have seen a gradual adoption of optional protocols to blend duck typing's flexibility with improved developer tools and static analysis, exemplified by Python's PEP 544 proposal in 2017, which formalized protocols for structural and was implemented in 3.8 in 2019, allowing seamless integration with existing duck-typed codebases. This trend reflects a broader movement toward in languages like and , where protocols serve as non-intrusive enhancements rather than strict mandates, promoting better code maintainability in large-scale dynamic systems.

Generics and Templates

Generics and templates represent compile-time mechanisms for achieving type-safe polymorphism in statically typed programming languages, enabling developers to parameterize classes, methods, and functions over types for reusable code. In Java, generics allow the definition of type parameters, such as in List<T>, where T can be substituted with any reference type, providing compile-time checks to prevent type mismatches that would otherwise occur at runtime. Similarly, C++ templates facilitate generic programming by allowing types, values, or other templates as parameters, with code instantiation occurring at compile time based on usage, thus avoiding runtime type overhead. These features promote abstraction without sacrificing the benefits of static typing, contrasting with duck typing's reliance on runtime behavior. A primary difference between generics/templates and duck typing lies in their enforcement of type constraints: generics impose static bounds or requirements that must be satisfied at , whereas duck typing permits any object exhibiting the necessary behavior at without prior declaration. For example, generics use bounded type parameters, like <T extends Number>, to restrict T to subtypes of Number, ensuring operations like are valid before completes. In C++, while traditional templates implicitly check structural compatibility during instantiation—accepting types that support required operations—explicit introduced in C++20 allow formal constraints, such as requiring a type to model a specific like "sortable," which duck typing resolves dynamically without such upfront validation. Despite these differences, generics and templates share similarities with duck typing in enabling polymorphic, reusable code that adapts to types based on capabilities rather than nominal declarations. C++ templates, in essence, implement a form of compile-time duck typing, where the only requirements on a template argument stem from its usage in the code, allowing flexible composition if the type provides the expected members or operations. Likewise, in C#, the where clause in generic declarations constrains type parameters to ensure they possess specific interfaces, base classes, or members—such as where T : IComparable<T>—thereby statically verifying behavioral compatibility in a manner that echoes duck typing's focus on functionality over strict type identity. One notable limitation of generics in static contexts is type erasure, particularly in , where generic type information is removed during compilation, replacing type parameters with their bounds (or Object if unbounded) to maintain with pre-generics . This erasure diminishes flexibility, preventing dynamic type checks or behaviors that duck typing supports seamlessly, as the operates on raw types without parameterized distinctions. In contrast, C++ templates generate specialized per type , preserving full type information at but at the cost of increased binary size.

Benefits and Challenges

Advantages

Duck typing offers significant flexibility in by allowing developers to integrate third-party libraries or modules without requiring adherence to predefined type hierarchies or explicit contracts, which fosters between components and eases extensibility. This approach enables across diverse contexts, as objects are evaluated based on their observable behaviors rather than their nominal types, reducing dependencies on specific class structures. The simplicity of duck typing lies in its elimination of boilerplate associated with declaring interfaces or enforcing type constraints upfront, streamlining code authorship and maintenance in dynamic languages. By focusing solely on the methods and attributes needed at , developers can prototype and iterate more rapidly, avoiding the overhead of formal type specifications that might otherwise complicate initial development phases. Duck typing naturally supports polymorphism, permitting the creation of concise and expressive that operates uniformly on heterogeneous data structures, provided they implement the requisite behaviors—for instance, treating any iterable object uniformly in list-processing operations. This behavioral compatibility allows for generic functions that adapt to varying input types without explicit parameterization, enhancing readability and adaptability. In terms of productivity, duck typing contributes to accelerated development cycles, particularly in scripting environments and web development frameworks such as , where the emphasis on behavioral enables quicker assembly of functional prototypes and reduces time spent on type-related refactoring.

Disadvantages

One significant drawback of duck typing is the deferral of type-related errors to , where mismatches in expected or attributes—e.g., a when a required is absent—only manifest during execution, often deep within call stacks, which complicates and increases the risk of unexpected failures in production environments. This late detection stems from the absence of compile-time verification, allowing incompatible objects to pass through interfaces until actively invoked. Refactoring under duck typing introduces substantial risks, as modifications to an object's methods or attributes can silently break distant, dependent code without any static warnings, making it challenging to trace and update all implicit usages across a project. The reliance on behavioral compatibility rather than explicit contracts obscures these dependencies, potentially leading to widespread regressions that are difficult to identify without comprehensive testing. In large codebases, duck typing exacerbates fragility due to the accumulation of implicit contracts, where subtle behavioral changes propagate unpredictably, hindering and . IDE support is also weaker compared to statically typed systems, as tools struggle to provide accurate autocompletion, , or error highlighting without explicit type information, slowing development in complex projects. To mitigate these issues, languages like introduced type hints starting with version 3.5 via PEP 484, enabling optional static analysis with tools such as mypy for early error detection and improved refactoring support. Linting tools further assist by enforcing conventions and catching potential type mismatches, though these strategies remain less comprehensive than mandatory compile-time checks in static languages, as they depend on voluntary adoption and do not alter runtime behavior.

References

  1. [1]
    3.3 Designing Data Types - Introduction to Programming in Java
    Duck typing. Duck typing is a programming style in which the language does ... You can make a user-defined type comparable by implementing the six ...
  2. [2]
    [PDF] Safety and strong versus weak typing - Cornell: Computer Science
    The term duck typing has been used for the type checking done by Python at runtime: "If it walks like a duck and it quacks like a duck, then it must be a duck.<|control11|><|separator|>
  3. [3]
  4. [4]
    What's New in Python 2.6 — Python 3.14.0 documentation
    Python has a strong tradition of duck-typing, where explicit type-checking is never done and code simply calls methods on an object, trusting that those ...
  5. [5]
    Protocol: keystone of Python type hints - Speaker Deck
    Alex Martelli in comp-lang-python, 2000-07-26 ... python-list/2000-July/046184.html Duck typing defined. TWO DIMENSIONS ...
  6. [6]
    Glossary — Python 3.14.0 documentation
    Duck-typing avoids tests using type() or isinstance() . (Note, however, that duck-typing can be complemented with abstract base classes.) Instead, it ...
  7. [7]
    Duck Typing in Python: Writing Flexible and Decoupled Code
    Duck typing is a type system where an object is considered compatible with a given type if it has all the methods and attributes that the type requires.Missing: origin | Show results with:origin
  8. [8]
    What is “duck typing”? | Fabulous adventures in coding
    Jan 2, 2014 · Duck typing is a system for deducing facts about entities in a program and then deciding whether the collection of facts in the program showed that all parts ...
  9. [9]
    Manifest Typing - C2 wiki
    ManifestTyping is a special case of StaticTyping. StaticTyping means that the language design requires each declaration to have a nontrivial type.
  10. [10]
    What is the difference between Latent type and Manifest type?
    Dec 19, 2009 · Manifest typing: The type of all variables declared are explicitly identified. ... I claim that there's not yet widespread agreement on what ...Inferred Type and Dynamic typing - Stack Overflowhow do i take advantage of sqlite manifest typing / type affinity using ...More results from stackoverflow.com
  11. [11]
    polymorphism (was Re: Type checking in python?) - Google Groups
    Jul 26, 2000 · In my experience, using the type() builtin is more pain than it's worth. I like the scheme proposed by Alex Martelli, except that I would have
  12. [12]
    Duck Typing Is More Than Quackery | You've Been Haacked
    Jan 4, 2014 · He continues with a description of structural typing that sounds like what he always thought “duck typing” referred to, but notes that his idea ...Missing: origin | Show results with:origin
  13. [13]
    How and when did it happen that, a type is an interface?
    Jan 3, 2016 · It actually sound exactly the same as Duck Typing, but Duck Typing seems like a new concept that began about in 2003 in the Python and Ruby ...
  14. [14]
    What Is Duck Typing? | Baeldung on Computer Science
    Apr 15, 2025 · Duck typing is a typing technique where an object is given a type if and only if it defines all the properties needed by that type.
  15. [15]
    Is duck typing a subset of polymorphism
    Nov 25, 2011 · Duck typing is not quite a subset of polymorphism, since ... class-based inheritance is just a form of polymorphism, not the only one.Why are inheritance and polymorphism so widely used?Why would many duck-typed dynamic programming languages use ...More results from softwareengineering.stackexchange.com
  16. [16]
    [PDF] Python - Lecture 3: OOP, Modules, Standard Library I - CS@Columbia
    Oct 1, 2014 · Polymorphism (2) - Duck Typing. ▷ Python is dynamically typed. Any variable can refer to any object. ▷ Explicit type checking (isinstance) ...
  17. [17]
    PEP 544 – Protocols: Structural subtyping (static duck typing)
    Mar 5, 2017 · In this PEP we specify static and runtime semantics of protocol classes that will provide a support for structural subtyping (static duck typing).
  18. [18]
    3. Data model
    Summary of each segment:
  19. [19]
  20. [20]
    Cycling and Looping—aka Iteration - Ruby in Twenty Minutes
    This method of not caring about the actual type of a variable, just relying on what methods it supports is known as “Duck Typing”, as in “if it walks like a ...
  21. [21]
    Array.from() - JavaScript - MDN Web Docs
    Jul 10, 2025 · The Array.from() static method creates a new, shallow-copied Array instance from an iterable or array-like object.Array.of() · Array.fromAsync() · TypedArray.from()Missing: duck | Show results with:duck
  22. [22]
    The arguments object - JavaScript - MDN Web Docs - Mozilla
    Jul 8, 2025 · arguments is an array-like object accessible inside functions that contains the values of the arguments passed to that function.Description · Assigning To Indices · Examples
  23. [23]
  24. [24]
    How can a statically typed language support duck typing?
    Aug 11, 2014 · Duck typing is for your typing convenience and in some languages for having generics (such as C++). Static typing is for checking the types you ...Is there a difference between duck typing and structural typing?From a software development lifecycle perspective, is duck-typing a ...More results from softwareengineering.stackexchange.com
  25. [25]
  26. [26]
    A Tour of Go
    ### Summary of Type Assertions in Go
  27. [27]
    Extensions - Documentation - Swift.org
    Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you don't ...
  28. [28]
    Documentation - Type Compatibility
    ### Summary of Structural Typing in TypeScript
  29. [29]
    Objects - Real World OCaml
    In fact, with a structural typing system like in OCaml, narrowing would essentially provide the ability to enumerate the methods in an object. To check ...
  30. [30]
    Impl trait type - The Rust Reference
    impl Trait provides ways to specify unnamed but concrete types that implement a specific trait. It can appear in two sorts of places.
  31. [31]
    [PDF] An Overview of Nominal-Typing versus Structural-Typing in Object ...
    Dec 29, 2017 · The sets of objects these type expressions denote are the same as record types well-known in the world of functional programming and among PL.
  32. [32]
    [PDF] Why Nominal-Typing Matters in Mainstream OOP - arXiv
    Dec 29, 2017 · Ex- amples of nominally-typed OO languages include many industrial-strength mainstream OO program- ming languages such as Java [44], C# [1], C++ ...
  33. [33]
    Interfaces and subtyping - Cornell: Computer Science
    Unlike some languages, Java does not allow this structural subtype relationships, but only nominal subtyping, in which subtypes are explicitly declared. There ...
  34. [34]
    [PDF] Integrating Nominal and Structural Subtyping
    Nominal subtyping allows programmers to explicitly express de- sign intent, and, when types are associated with run time tags, enables run-time type tests and ...
  35. [35]
    Type system - Kotlin language specification
    Kotlin uses nominal subtyping, meaning subtyping relation is defined when a type is declared, with bounded parametric polymorphism, implemented as generics via ...Missing: duck | Show results with:duck
  36. [36]
    typing — Support for type hints — Python 3.14.0 documentation
    Type-checker-agnostic documentation written by the community detailing type system features, useful typing related tools and typing best practices.Python 3.10.19 documentation · 3.9.24 · Static Typing with Python · Specification
  37. [37]
    Lesson: Generics (Updated) (The Java™ Tutorials > Learning the Java Language)
    ### Summary of Java Generics from https://docs.oracle.com/javase/tutorial/java/generics/index.html
  38. [38]
  39. [39]
    [PDF] Concepts: The Future of Generic Programming
    Concepts complete C++ templates as originally envisioned. I don't see them as an extension but as a completion. Concepts are quite simple to use and define ...
  40. [40]
    [PDF] Foundations of C++ - Bjarne Stroustrup
    The only requirements on a template argument are imposed by its use; this is “duck typing. ... Velthuizen: C++ Templates are Turing Complete. University of ...
  41. [41]
    where (generic type constraint) - C# reference - Microsoft Learn
    Jul 30, 2024 · The where clause in a generic definition specifies constraints on the types that are used as arguments for type parameters in a generic type, method, delegate, ...Missing: duck | Show results with:duck
  42. [42]
    [PDF] Dynamically Typed Languages | tratt.net
    Mar 13, 2009 · The advantages of static typing ... A good example of the virtues of duck typing can be found in Python where functions that deal with files often ...
  43. [43]
    Duck Typing in Python - GeeksforGeeks
    Jul 12, 2025 · Duck Typing is a type system used in dynamic languages. For example, Python, Perl, Ruby, PHP, Javascript, etc. where the type or the class of an object is less ...
  44. [44]
    Duck, Duck, Code: An Introduction to Python's Duck Typing
    Jul 3, 2024 · Duck typing is a concept in programming often related to dynamic languages like Python, that emphasizes more on the object's behavior over its type or class.
  45. [45]
    Making Ruby Quack—Why We Love Duck Typing - SitePoint
    Nov 6, 2024 · Duck typing is a highly appreciated feature of Ruby, which allows developers to write concise, clean, and readable code with minimal effort.
  46. [46]
    Dynamic typing - CS 242
    Pros: type-safe, no runtime errors, little syntactic overhead. ... (This idea is also called “duck typing”, although I never found the term very informative.) ...
  47. [47]
    (PDF) Static Typing Where Possible, Dynamic Typing When Needed
    This paper argues that we should seek the golden middle way between dynamically and statically typed languages.
  48. [48]
    PEP 484 – Type Hints - Python Enhancement Proposals
    This PEP aims to provide a standard syntax for type annotations, opening up Python code to easier static analysis and refactoring.
  49. [49]
    Static Type Checking in Python: Where Did the Ducks Go?
    Oct 13, 2021 · Duck typing is great for prototyping but pretty fragile in large systems. However, Pythonistas like the simplicity of duck typing.