Could Python supplant Java?

Peter Hansen peter at engcorp.com
Wed Aug 21 16:24:26 CEST 2002


Nicola Musatti wrote:
> 
> Peter Hansen wrote:
> [...]
> > I might have thought the same a year ago, but since then I've adopted
> > test-driven development (TDD) which grew out of XP.  Refactoring like
> > this becomes a breeze with a set of tests you can count on to check
> > not only the types of your objects, when that's important, but also
> > the logic, the inputs and outputs, and anything else that could
> > reasonably fail.  With static typed languages, you get only the one
> > fairly trivial type of checking.
> >
> > TDD and Python are an *excellent* fit, since TDD benefits greatly from
> > Python's very dynamic nature and flexilibity, while TDD supports
> > Python almost perfectly in one area where it seems many feel it has
> > a weakness - compile-time error checking.
> 
> So you rewrite a compiler worth of tests on each project? This almost
> sounds as a good reason to stick to statically typed languages: at
> least, half the tests have already been written for you.

Not at all.  I suspect effectively *none* of my tests are testing
that the types of data are correct, which is all the compiler does
for you.  

What they are testing is whether the data performs in the correct way
and produces the correct results.  That's all that matters, and the 
compiler gives you zilch in that respect.

It's like putting isinstance() at the top of functions to check that
they are passed the right types... pointless most of the time in Python
when you can just try *using* the object and if it works, that's all
you care.  So what if it's a mock file object that can be .read() but
not written?  If the function using it doesn't use .write() then the
special object will work just fine.  A compiler would tell me that
code is wrong, but it would be lying and preventing me from doing my
job efficiently...

-Peter



More information about the Python-list mailing list