Python less error-prone than Java

D H no at spam.please
Sun Jun 4 10:07:34 EDT 2006


Christoph Zwerschke wrote:
> 
> See the following web page if you dont find it ;-)
> http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html 

The point of that is that it did fail.  It threw an 
ArrayIndexOutOfBoundsException exception.  But it was just luck that 
happened.  Unfortunately I don't think java and C# have integer overflow 
checking turned on by default.

Take this longArithmetic benchmark here:
http://www.cowell-shah.com/research/benchmark/code
and a story about it here:
http://www.osnews.com/story.php?news_id=5602&page=3

The java and C# versions are fast (15 seconds for me), BUT, they
give the incorrect result because of an overflow error.
The python version gives the correct result because it transparently
changes the underlying types to handle the larger numbers, BUT this
causes it to run over 20X slower than Java or C#.  It takes 10 minutes
to complete in python, not 15 seconds.  With psyco, it takes 5 minutes.

So to say the story you pointed out shows that python is superior
is a matter of perspective.  Yes, python gave the correct result
by silently changing the underlying types to longs, and that is
what I would expect of a scripting language.  But the price is
speed.  In both these cases, I would rather be made aware of the
error in the code and fix it so I didn't have to suffer slowdowns.

That is why in boo ( http://boo.codehaus.org/ ) luckily overflow 
checking is enabled by default, and it throws a overflow exception at
runtime to tell you something is wrong with your code.  When you
then fix for that, you get the same 15 second time just like java
and C#.



More information about the Python-list mailing list