Correct code/unit testing (was Re: Efficient python programming...)

Peter Hansen peter at engcorp.com
Sun Jun 9 17:51:14 EDT 2002


"John J. Lee" wrote:
> 
> > Kragen Sitaker wrote:
> > > It is certainly possible to err too far in the direction of believing
> > > your code correct simply because it passes its test suite, and this is
> > > a common beginner's error.  I think it is also possible to err too far
> > > in the direction of writing and running tests instead of desk-checking
> > > code.
> 
> Isn't it true that, however much time you're going to spend, the largest
> number of bugs are going to get removed by allocating some of the time to
> both activities: testing, and staring at the code?

Perhaps, assuming you put a lot of bugs in the code, some amount of staring
will be necessary.

I believe staring is of little or no use, however, having tried it many 
times with my and others' code which had bugs and not having found those 
bugs by staring.

The nastiest bugs were found by lots and lots of work, which usually
included repeated attempts to reproduce the problem, manual runs, 
and sometimes using a debugger.  Staring helped little.  And then,
having found the bug, we look at the code and say "oh yeah, we 
should have seen that." 

Better not to put the bugs in the code in the first place, however,
so staring or those other things won't be necessary.  Writing the 
tests and the code together, tests first, in small iterative steps, 
tends not to lead to buggy code.  The payback is high compared to
staring.

-Peter



More information about the Python-list mailing list