Interface and duck typing woes

Joe Junior joe.fbs.junior at gmail.com
Thu Aug 29 08:40:32 EDT 2013


Well, the main reason for me asking this question here was because of
the Java/C#/Whatever developer in me craving for an Interface for the
container's items, and I noticed that I'm not alone in this. But I was
actually expecting the "We're all consenting adults, here", I guess I
just needed the confirmation :-)

Another reason for this question is that I read some people saying
they wouldn't use python for large projects, and they always point at
the lack of Interfaces as a concern. I actually disagree, but I can
see their point. What do you think?

@Nobody
>> Of course I don't want to check isistance(), I like duck typing, but
>> should I check if hasattr() and callable() before adding to the container?
>That won't tell you if the object has a quack() method but with
>incompatible semantics (e.g. wrong number or types of arguments).

Yeah, didn't think about that, it's kinda swimming upstream!
Definitely it is more hassle than it is worth.

@ChrisA
>Do you believe that you can write code to catch every bug you might
>make? If so, you are naive and probably haven't spent much time
>programming yet :) And if not, then you must acknowledge that bugs
>WILL happen; therefore you will need to cope with them after the
>event. So rather than trying to prevent them all, just improve your
>means of coping, and you'll accomplish the same end with much less
>trouble.

Oh, no! I'm not that presumptuous (or naive)! But what do you mean by
"improve means of coping"? Do you know any article on the subject you
could point me?

@Steven
>> Of course I don't want to check isistance(), I like duck typing, but
>> should I check if hasattr() and callable() before adding to the
>> container? What is the pythonic way to deal with it? Am I worrying too
>> much ;-)?

>Yes :-)

Well, thanks! :-) And thanks for the article.



More information about the Python-list mailing list