[Python-Dev] When to signal an error (original) (raw)

Jason Orendorff jason@jorendorff.com
Sat, 19 Jan 2002 17:34:12 -0600


Guido van Rossum wrote:

Jason Orendorff wrote: > At runtime, Python tends to complain about iffy situations, > even situations that other languages might silently accept.

"Other languages" being Perl or JavaScript? The situations you show here would all be errors in most languages that are compiled to machine code. > For example: > print 50 + " percent" # TypeError > x = [1, 2, 3]; x.remove(4) # ValueError > x = {}; print x[3] # KeyError > a, b = "x,y,z,z,y".split() # ValueError > x.append(1, 2) # TypeError, recently > print u"\N{EURO SIGN}" # UnicodeError

Not to bicker, but Java only manages to reject 2 of the 6, both at compile time. The other 4 silently pass through the standard library without complaint. None cause exceptions during execution.

ML makes no distinction between append(1, 2) and append((1, 2)), but that's a syntax thing... C++ STL remove() doesn't complain if it doesn't find anything to remove; nor does the C++ map<>::operator complain if no entry exists.

> I'm not complaining. I like the pickiness.

That's why you're using Python. :-)

(laugh) You sell yourself short, Guido. :) I would still use Python even if (50 + " percent") started evaluating to "50 percent" tomorrow.

Jason Orendorff http://www.jorendorff.com/