Duck typing
Jump to navigation
Jump to search
Duck typing is named for "If it walks like a duck and quacks like a duck, it must be a duck."
In programming, it is the attitude that
as long as a value/object always behaves like we expect when we interact with it,
it doesn't really matter what precise type it actually is.
This is mostly a concept around dynamic typing,
where this attitude can save a bunch of keystrokes and text in code that is necessary primarily or only to make the compiler happy.
If this sounds like playing loose, then yes - indeed it can be abused in really fragile and opaque ways.
Or well. Up to you, the programmer.