does lack of type declarations make Python unsafe?

Peter Hansen peter at
Mon Jun 16 18:18:06 CEST 2003

David Abrahams wrote:
> I find that static typing makes a big difference for two things:
>   2. Refactoring.  Having a compiler which does some static checking
>      allows me to make changes and use the compiler as a kind of
>      "anchor" to pivot against.  It's easy to infer that certain
>      changes will cause compiler errors in all the places where some
>      corresponding change needs to be made.  When I do the same thing
>      with Python I have to crawl through all the code to find the
>      changes, and a really complete set of tests often take long
>      enough to run that using the tests as a pivot point is
>      impractical.

I just went through a particularly straining session of refactoring

I couldn't get my head around how to do what I wanted to do, but I
kept bashing away at it, trying one thing, then another.  (One of
my problems is that I'm still a little new at using generators, and
I was trying to use a generator at the heart of the solution.)

At no time was I actually changing the interface to any of my
functions, changing order of arguments or their types.

At no time did I actually encounter a syntax error or any other
kind of error which stopped the code from running.

At no time did I make a single mistake which would have been
caught by the compiler for a statically typed language.  I
was on a roll I guess, typing accurately and not doing anything

Nevertheless, I repeatedly injected logic errors and other such
problems into the code as I tried to change its structure.

My tests helped me though.  I'd guess I had to back out of at
least five different false directions, as one after another
obscure test popped up, tapped me on the shoulder, and said,
"Uh, excuse me?  What am I, chopped liver?  I need to pass too!"

Not proof of anything, or disproof, either, I suppose.  Just a
little reflection on refactoring and the value of tests and
static type checking.


More information about the Python-list mailing list