Duck typing

From Wiki @ Karl Jones dot com
Jump to: navigation, search

In computer programming, duck typing is an application of the duck test in type safety. It requires that type checking be deferred to runtime, and is implemented by means of dynamic typing or reflection.

Description

Duck typing is concerned with establishing the suitability of an object for some purpose. With normal typing, suitability is assumed to be determined by an object's type only. In duck typing, an object's suitability is determined by the presence of certain methods and properties (with appropriate meaning), rather than the actual type of the object.

The analogy to the duck test appeared in a Python Enhancement Proposal discussion in 2002.

See also

External links