Interface and duck typing woes

Cameron Simpson cs at zip.com.au
Wed Aug 28 21:20:20 EDT 2013


On 29Aug2013 09:17, Chris Angelico <rosuav at gmail.com> wrote:
| On Thu, Aug 29, 2013 at 7:54 AM, Terry Reedy <tjreedy at udel.edu> wrote:
| > Depending on who the users will be, I might just not worry about it until an
| > exception is raised. If you try to protect against everything that you might
| > do wrong, you are on the road to madness, as the protection code might also
| > be buggy. (Too much testing has the same problem ;-).
| 
| I'd go further.
| 
| 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.

I'm not so extreme. Yes, of course certain things will only show
at runtime and you should be prepared to have to deal with that.

However, when working in Java its type strictness caught a great
many simple brainfart logic errors by checking function signatures;
typically calling the wrong function/method or mangling arguments.
Getting this stuff up front was handy. Of course there's a price
there in terms of flexibility and all that wordy stuff defining the
functions in the first place. As an aside, you can also get a lot
of this checking in C with aggressive linting and making a bunch
of macros like:

  #define CNULL ((char *)NULL)
  #define CPNULL ((char **)NULL)

and so forth as needed - lint can then catch a lot of otherwise
unchecked comparisons.

Anyway, I digress. My point is that there are plusses to having
signature/type checking at coding time. It is not the Python Way,
but I surely cannot be alone in sometimes being frustrated chasing
a deeply nested runtime error that static type checking might have
found up front.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

"waste cycles drawing trendy 3D junk"   - Mac Eudora v3 config option



More information about the Python-list mailing list