A distillation of duck typing
style="margin-left: 40px;"> style="font-family: Comic Sans MS; font-style: italic;">"Substitution
of an object with regard only of the function and signature style="font-family: Comic Sans MS; font-style: italic;">of
its run-time methods style="font-family: Comic Sans MS; font-style: italic;">"
Mainly Tech projects on Python and Electronic Design Automation.
Friday, July 04, 2008
Essence of Duck
Lets
break it down:
- style="font-family: Comic Sans MS; font-style: italic;">Substitution
- Its
about the later use of a new object type instead of another . style="font-family: Comic Sans MS; font-style: italic;">object - Its
about the use of data types. style="font-family: Comic Sans MS; font-style: italic;">regard - What
needs to be in place for things to work. style="font-family: Comic Sans MS; font-style: italic;">function - what
the substituting object has to do to fit in. style="font-family: Comic Sans MS; font-style: italic;">signature - the
substituting objects method signature needed for
compatability. style="font-family: Comic Sans MS; font-style: italic;">run-time - It
is what actually happens at run time that matters without the
constraint of what can be determened at compile time.
of type-checking, class hierarchy checking, in fact any 'look before
you leap' checks. Note too, that I purposefully put function before
signature - too many comments on duck typing focus on issues
of signature and assume
programmer checks for correct substitutable function are style="font-style: italic;">not part of duck
typing.
- - Paddy.
...and attributes, sometimes.
ReplyDelete