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

holger krekel pyth at devel.trillke.net
Sun Jun 9 05:17:15 EDT 2002


Peter Hansen wrote:
> Kragen Sitaker wrote:
> > I think (and extensive experimentation has
> > shown) that careful reasoning and code reviewing is necessary and
> > sufficient to write correct code.
> 
> Whoa!  "extensive experimentation has shown"??  I would suggest that
> what extensive experience (I change the word deliberately) has shown
> many of us is that careful reasoning and code reviewing, no matter
> how extensive, will *always* leave bugs in the code.  Have you never
> spent a large amount of time carefully designing and coding a wonder
> little program, and checked it over very carefully, even with a peer,
> and later found a bug in it?  Maybe you're just a better programmer
> than I, and many others, but I would say this inevitable outcome is 
> the source of the term "egoless programming" -- if you have a big
> ego, you'll be devastated by the repeated proof that you will never,
> ever get it right the first time, or even after lots of reviewing.

I mostly agree and there is even another point that makes tests
important: making sure that later changes do not break
the basic semantics of your program. You would have to do another
code review of the *whole* part of a program to gain confidence, again.
This method doesn't scale well with the number of changes to a program.
Only if you ever touch code once in a year would you affort to gain 
confidence by 'closely examining the code'. Most often, people just
assume that their clever modification will not do any harm...

I must admit that writing tests for C++ or Java code really 
is a verbose pain.  But with python it's almost fun.

just my 2 test cent,

    holger





More information about the Python-list mailing list