Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8544973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:41:11+00:00 2026-06-11T12:41:11+00:00

I searched through SO for a while and I could not find a definite

  • 0

I searched through SO for a while and I could not find a definite and general answer, only some contradictory and particular opinions. [1]

So I would like to know what is the relationship between duck typing and generic programming? ( DT < GP , DT == GP, DT > GP ) . By generic programming I refer to ,in particular, C++ templates or Java generics, but a general answer, related to the concepts, if it’s possible, would be welcomed.

I know that generic programming will be handled at compile time, while duck typing will be handled at runtime, but appart of this I do not know how to position them.

Lastly, I do not want to start a debate, so I would prefer answers like reasons for, reasons against.

[1] What's the relationship between C++ template and duck typing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:41:11+00:00Added an answer on June 11, 2026 at 12:41 pm

    I have encountered two different definitions of “Duck Typing”. No doubt there are people who will tell you that one of them is “correct” and the other is “incorrect”. I merely attempt to document that they’re both used rather than tell you that they’re both “correct”, but personally I see nothing wrong with the broader meaning.

    1) runtime-only typing. Type is a property of objects, not variables, and hence necessarily when you come to call a method on an object, or otherwise use properties that it has by virtue of its type, the presence or absence of that method is discovered at runtime[*]. So if it “looks like a duck and quacks like a duck” (i.e. if it turns out to have a quack() function) then it “is” a duck (anyway, you can treat it like one). By this definition of course C++ templates fall at the first hurdle, they use static typing.

    2) A name used more generally for the principle that if it looks like a duck and quacks like a duck then it is a duck, to mean any setup in which interfaces are implicitly defined by the operations performed by the consumer of the interface, rather than interfaces being explicitly advertised by the producer (whatever implements the interface). By this definition, C++ templates do use a kind of duck-typing, but whether something “looks like a duck” is determined at compile time, not at runtime, based on its static type rather than its dynamic type. “Check at compile time, can this variable’s static type quack?”, not “check at runtime, can this object quack?”.

    The dispute seems to me in effect to be over whether Python “owns” the term, so that only Python-like type systems can be called duck typing, or whether others are free to appropriate the term to mean a similar concept in a different context. Whatever you think it should mean, it seems irresponsible to use a “jokey” term and demand that everyone understands the same formal definition from it. SO is not a suitable forum to tell you what a term “should” mean, unless there’s an authoritative source that you’re asking about, like a dictionary or any academic papers that define it formally. I think it can tell you what it’s actually used to mean.

    “Generic programming” can make use of duck typing or not, depending on the exact details. C++ generic containers do use “type 2” duck-typing, because for a general type in C++ it’s not guaranteed that you can copy it, compare it, get a hash value, etc. Java generic containers don’t, Object has enough methods already to make it hashable etc.

    Conversely, I suspect that anything you do that uses duck typing, can reasonably be referred to as “generic programming”. So I suppose, in the terms you asked for, GP > DT in that duck typing (either definition) is a strict subset of the vast range of stuff that can be called “generic”.

    [*] well, in some cases your dynamic language could have some static analysis that proves the case one way or the other, but the language demands the ability to defer this check until runtime for cases where the static analysis cannot conclusively say.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I searched through here as best I could and though I found some relevant
i searched through Stack overflow but fail to find a solution in regards to
I have searched through many times but have not seen this before. Probably really
I've searched on SO for a while on this but cannot find a definitive
I've searched around and couldn't quite find the answer to my question. What is
I have searched through internet & found that there are no any direct method
I've searched through the web and what I've found out is this: To make
I've searched through the other expected Class Name error questions on here, but they
although I searched through existing threads for my problem I havent found a solution
I've searched through the documentation and searched around but there is nothing said about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.