Chris Angelico writes:
On Sat, Apr 24, 2021 at 10:14 AM Nick Coghlan <ncoghlan@gmail.com> wrote:
Duck typing usually falls squarely into the EAFP category.
Isn't it orthogonal?
Not really. If you ask 'thing' to 'thing[0]', you don't find out whether it is a list or a dict (or any number of other things, for that matter). EAFP can only verify the presence of the facilities you actually use, not what thing is, so it *implies* duck-typing. Nick's statement is not even close to a logical implication, as you point out, but I think it's the state of the art. The question I have is whether that's something essential about duck-typing, or if perhaps as Gregory points out it's that we don't have TOOWDTI for LYBL duck- typing. It's interesting in this regard that so much effort goes into strict typing and pattern matching which (so far) are LYBL concepts, while EAFP + duck-typing is "No Reason," "Just Do It" and nobody seems to have a big problem with that once they get used to it. :-)