diff options
author | Raymond Hettinger <python@rcn.com> | 2005-01-11 16:14:55 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-01-11 16:14:55 (GMT) |
commit | edce3137060e7783818b6c6888da120909cd95b1 (patch) | |
tree | 03eb9e8a6167bc5716ab2fcac415ceb5df943e48 | |
parent | fe165c1d32f9b12fd1efb8e2f69fd331dec074b3 (diff) | |
download | cpython-edce3137060e7783818b6c6888da120909cd95b1.zip cpython-edce3137060e7783818b6c6888da120909cd95b1.tar.gz cpython-edce3137060e7783818b6c6888da120909cd95b1.tar.bz2 |
Add duck-typing to the glossary.
-rw-r--r-- | Doc/tut/glossary.tex | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/tut/glossary.tex b/Doc/tut/glossary.tex index b0ac97f..7f04a79 100644 --- a/Doc/tut/glossary.tex +++ b/Doc/tut/glossary.tex @@ -85,6 +85,17 @@ use of \class{dict} much resembles that for \class{list}, but the keys can be any object with a \method{__hash__()} function, not just integers starting from zero. Called a hash in Perl. +\index{duck-typing} +\item{duck-typing} +Pythonic programming style that determines an object's type by inspection +of its method or attribute signature rather than by explicit relationship +to some type object ("If it looks like a duck and quacks like a duck, it +must be a duck.") By emphasizing interfaces rather than specific types, +well-designed code improves its flexibility by allowing polymorphic +substitution. Duck-typing avoids tests using \function{type()} or +\function{isinstance()}. Instead, it typically employs +\function{hasattr()} tests or {}\emph{EAFP} programming. + \index{EAFP} \item[EAFP] Easier to ask for forgiveness than permission. This common Python |