PEP 3107 and stronger typing (note: probably a newbie question)

Diez B. Roggisch deets at nospam.web.de
Sun Jul 1 06:33:12 EDT 2007


> 
> """
> Because of the different flight path, a data conversion from a 64-bit 
> floating point to 16-bit signed integer value caused a hardware 
> exception (more specifically, an arithmetic overflow, as the floating 
> point number had a value too large to be represented by a 16-bit signed 
> integer).
> """
> 
> As far as I'm concerned, it surely qualifies as a runtime type error - 
> "data conversion from a floating point to a 16-bit signed int" should 
> not be allowed when unsafe, isn't it ?

I wouldn't say so. The conversion is a partial function. It _has_ to be 
a partial function, as you can't cram 64 bit into 16 without losses. If 
you could, infinite compression would be possible.

So - you _have_ to allow such a conversion. That has nothing to do with 
types, the types were proper. The values weren't.


> """
> Efficiency considerations had led to the disabling of the software 
> handler (in Ada code) for this error trap.
> """
> 
> Which implies that even in ADA, runtime type errors are in fact expected 
> - else there would be no handler for such a case.

Well, yes, runtime errors occur - in statically typed languages as well. 
That's essentially the halting-problem.


 > But what, how could an ADA module not be correct if it compiles - the
 > ADA type system is here to "prove the absence of certain bugs", isn't
 > it ?-)


Yes, certain bugs. Not those though. In the same sense as the python 
compiler pukes statically on me if I write

def f():
    n = x * 2
    x = n


The whole point of the Ariane failure was that nobody believed in the 
code because the type analyzer had woven it through - but because the 
specs and a mathematical analysis of the code had shown it was to be 
trusted. For the old rocket, that was.

The question is not if static typing that prevents certain errors is a 
bad thing. It's not. But it comes with a pricetag - the lack of 
flexibility. And usually, I'm not willing to pay that price, because it 
makes my whole design much more cumbersome and thus often error-prone - 
as line numbers increase.

But in a constrained environment like the ariane, where you have limited 
resources, you want as much certainity as you can get, together with 
operations that run on the native types of your processor in an 
efficient way.


Diez



More information about the Python-list mailing list