Python less error-prone than Java
Alex Martelli
aleax at mac.com
Sat Jun 3 20:07:48 EDT 2006
Simon Percivall <percivall at gmail.com> wrote:
...
> with static typing. The equivalent in Python would have been if an
> overflow exception was raised when the int got too big. It might have
> been that way, typing or no typing.
Indeed, it _used_ to be that way --
<http://docs.python.org/lib/module-exceptions.html> STILL says...:
exception OverflowError
Raised when the result of an arithmetic operation is too large to be
represented. This cannot occur for long integers (which would rather
raise MemoryError than give up). Because of the lack of standardization
of floating point exception handling in C, most floating point
operations also aren't checked. For plain integers, all operations that
can overflow are checked except left shift, where typical applications
prefer to drop bits than raise an exception.
Actually, the docs are obsolete on this point, and an int becomes a long
when that's necessary:
>>> sys.maxint+1
2147483648L
but, this operation _would_ have raised OverflowError in old-enough
versions of Python (not sure exactly when the switch happened...).
Alex
More information about the Python-list
mailing list