What is Duck Typing in programing (2025)

By Xah Lee. Date: . Last updated: .

what's duck type in programing

duck typing 2026-11-24 36c57 L
duck typing 2026-11-24 36c57 L

If it walks like a duck and quacks like a duck, but it bleeds blue, is it a duck? have you checked?

Duck type, one of the idiotic concept, a fad, by brogramers.

An opaque jargon. The word doesn't convey what it means. Sloppy, lose, meaningless. It serve as a promotion slogan for python basically.

Duck Typing Example

# 2025-10-02
# duck typing error example.
# code from grok ai

def make_it_quack(thing):
    thing.quack()  # No type check; assumes it has this method

class Duck:
    def quack(self):
        print("Quack!")

class Person:
    def quack(self):  # A person can "quack" too
        print("I'm quacking like a duck!")

# This works fine
duck = Duck()
person = Person()

make_it_quack(duck)   # Output: Quack!
make_it_quack(person) # Output: I'm quacking like a duck!

# But this would raise an AttributeError at runtime
class Car:
    pass  # No quack method

make_it_quack(Car())  # Error: 'Car' object has no attribute 'quack'