Python less error-prone than Java

Christoph Zwerschke cito at online.de
Sun Jun 4 17:14:22 EDT 2006


nikie wrote:
 > Hm, then I probably didn't get your original point: I thought your
 > argument was that a dynamically typed language was "safer" because it
 > would choose the "right" type (in your example, an arbitrary-pecision
 > integer) automatically.

No, my point was not to make a general statement. It just stumbled over 
that example and said to myself "that wouldn't have happend with 
Python." And I thought it might be interesting for people on c.l.p as 
well. That was all.

 > As you can see from the above sample, it
 > sometimes picks the "wrong" type, too. Now you tell me that this
 > doesn't count, because I should have told Python what type to use.

Yes. Python did not "pick" that type - you explicitely said that x 
should an int by setting x = 10001.

 > I mean, you could have told Java to used a 64-bit or arbitrary-length
 > integer type instead of a 32-bit integer (which would actually be
 > equivalent to the Python code), so it would do the same thing
 > as the Python binary search implementation.

Right, but then Java would do all index operations in that type, even 
for very small arrays when it's not necessary. That's why people 
probably don't do it.

 > The is OT, but what makes you think a C# decimal can't store 0.01?

A C# data type summary gave me the impression that it was just a more 
accurate but still binary floating point type. But you're right, the 
name "decimal" should have given me a clue that it uses base 10 ;-)

So sorry for the confusion. Forget what I wrote about float. I should 
have corretly written that the equivalent to the C# statement

decimal x = 10001;

is the following Python statement

x = Decimal(10001)

If you do the equivalent thing, Python will give the same result as C#.

 > All I wanted to point out is that bounded integers do have their
 > advantages, because some people in this thread apparently have
 > never stumbled over them.

Sure, I did not want to deny that. The main advantages are speed, and 
dealing with hardware related issues. Your Distance function in C is of 
course much faster than my Python implementation. Surely I wouldn't want 
to write a device driver in Python.

-- Christoph



More information about the Python-list mailing list