Efficient python programming...

holger krekel pyth at devel.trillke.net
Sat Jun 8 01:46:58 CEST 2002


Peter Hansen wrote:
> holger krekel wrote:
> > Peter Hansen wrote:
> > > You forgot the even more important first thing for a beginner:
> > > get it correct!  The only good way to do this is to write unit
> > > tests that prove it.  If you don't have tests, you don't have
> > > working code (or how can you prove it?).
> > 
> > yeah. writing tests is *the way* to go if you want other people use
> > your code. Although successfull unittests theoretically don't prove
> > anything<wink> they tend to do in reality<doublewink>.
> 
> Could you explain why you think unittests don't prove anything 
> when they are successful?

I meant to play with the academic notion ('theoretically') of 
proving algorithms to be correct.  From a stricter perspective
unittests are just examples and examples do not prove anything. 
But 'in reality' they do prove that intended usage of an API 
basically works and nothing broke while fixing bugs or adding 
new features. 
 
> Are you pointing out that if you write a test after the code
> and the test passes, you have learned almost nothing?  I agree
> with that.
> 
> With Test-Driven Development, however, you write the test first,
> run it immediately, and ensure that it fails.  Only after you
> have code that makes it pass are you done.
> 
> In this case, making sure the test fails when the code is wrong,
> wouldn't you say that the test mostly proves that the code works?

*Mostly*, yes.  Unfortunately mathematicians impose a boolean
view regarding proofs on us poor coders: proven or not proven. 
 
> (Not quibbling about the fact you are still not 100% sure...)

which was the whole point of my posting :-)

    holger





More information about the Python-list mailing list