Could Python supplant Java?
Nicola.Musatti at ObjectWay.it
Wed Aug 21 17:45:39 CEST 2002
Peter Hansen wrote:
> 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.
I'm not surprised. I'm also convinced that the way you exploit typing in
Python is very different from the way I exploit it in C++.
> 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.
Not true, because I try to express as much of the semantics of my
programs through types so as to get as much help from the compiler as I
can. This is certainly far from enough, but I'm convinced that there are
several kinds of problems in which the help is real. On the other hand
there also are problems where static typing provides very little help:
text manipulation comes to mind.
> 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.
It's not that the test is useless, it is redundant as Python's runtime
performs the check for you.
> 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...
It depends. This is very similar to what I achieve by combining
templates and overloading.
When all's said and done, I'm convinced that static typing and dynamic
typing have both strengths and weaknesses that proficient programmers
exploit. What I'm not convinced of is that dynamically typed languages
are better than statically typed ones in all respects.
More information about the Python-list