Interface and duck typing woes

Roy Smith roy at panix.com
Wed Aug 28 21:27:34 EDT 2013


In article <mailman.339.1377739246.19984.python-list at python.org>,
 Cameron Simpson <cs at zip.com.au> wrote:

> 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.

One time when I really do miss static typing (and often emulate by 
sprinkling isinstance() assertions into my functions) is when I do a big 
refactoring.

I'll change (to pick a real example) Song.get(id) from taking an integer 
to taking an ObjectId.  I'll hunt through my source code to find all the 
places where I call Song.get(), but usually I'll miss a few.  The 
assertions will help me catch that quickly because I'll get an easy to 
understand exception thrown right at the first point of contact, rather 
than something cryptic happening 12 stack frames down, deep in the 
database layer.



More information about the Python-list mailing list