"static" checking

Peter Hansen peter at engcorp.com
Thu Jan 29 09:41:14 EST 2004


Moosebumps wrote:
> 
> I'm wondering what kind of checking I can do on a python program before
> running it (besides reading over every line).  I hate running a long python
> script, only to have it fail at the end because I misspelled a function
> name, or made some other silly mistake that a compiler would normally catch.
> Then I have to run it all over again to see what happened or come up with
> some sort of short test.
> 
> I usually do try to isolate the new parts of my code, and run them first
> with some dummy data that will run fast.  But that is not always possible
> because of dependencies, and it would be nice to have some sort of sanity
> check up front.

These issues largely go away once you start doing test-driven development.
See, for example, Mark Pilgrim's excellent introduction in his book at
http://www.diveintopython.org/ (see the link under "unit testing"), or 
Kent Beck's paper book "Test-Driven Development" (published by Addison Wesley).

With this approach, your code generally won't have those dependencies 
(sometimes the approach has to be tried before someone can really believe
that, but it's true) and you find your spelling mistakes, and many other
problems that static checking can't find, in seconds without no more
effort than it takes to run a batch file.

-Peter



More information about the Python-list mailing list