What's Duck Type in Programing
what's duck type in programing
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. (those sans computer science background)
An opaque jargon. The word doesn't convey what it means. Sloppy, lose, meaningless. It serve as a promotion slogan for python basically.
basically, it just means, the programing language does not check type correctness, it has advantages in quikies, but to make it more lovable, we defend it by saying it's duck typing.
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' # Quack! # I'm quacking like a duck! # Traceback (most recent call last): # File "c:\Users\xah\.emacs.d\temp\20251002_0856_c05f.py", line 27, in <module> # make_it_quack(Car()) # Error: 'Car' object has no attribute 'quack' # ^^^^^^^^^^^^^^^^^^^^ # File "c:\Users\xah\.emacs.d\temp\20251002_0856_c05f.py", line 6, in make_it_quack # thing.quack() # No type check; assumes it has this method # ^^^^^^^^^^^ # AttributeError: 'Car' object has no attribute 'quack' # Process xah-run exited abnormally with code 1