Could Python supplant Java?

Nicola Musatti Nicola.Musatti at ObjectWay.it
Wed Aug 21 09:51:30 EDT 2002


Duncan Booth wrote:
> 
> Nicola Musatti <Nicola.Musatti at ObjectWay.it> wrote in
> news:3D6356C5.56BD3D63 at ObjectWay.it:
> 
> > 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.
> 
> Unfortunately the tests the compiler does aren't generally the most useful.
> If you have a function that is supposed to return the total of a list of
> numbers, the compiler might check that you pass in a list of numbers and
> get back a single number as a result. The tests you write may tell you that
> when you pass in the list [1, 2, 3] you get back 6, and when you pass in []
> you get an IndexError exception.
> 
> I know which of these I would prefer to have.

Both, I would say. The test the compiler performs for you is
semantically very poor, but is performed on all the *users* of your
function (i.e. checks very little in a lot of places). The test you
write is semantically rich, but in itself doesn't give any guarantee
that users of the function use it as it is meant to.

Maybe Bertrand Meyer was right all along and language enforced design by
contract is the superior strategy.

Anyway, I'm well aware that compilers do not prove code to be correct.
On the other hand Peter's message seemed to imply that part of the tests
you should write for a Python application do address Python's lack of
static typing.

Cheers,
Nicola Musatti



More information about the Python-list mailing list