does lack of type declarations make Python unsafe?
danb_83 at yahoo.com
Mon Jun 16 05:04:10 CEST 2003
beliavsky at aol.com wrote in message news:<3064b51d.0306151228.22c595e0 at posting.google.com>...
> In Python, you don't declare the type of a variable, so AFAIK there is
> no way for the interpreter to check that you are calling functions
> with variables of the correct type.
> Thus, if I define a function correl(x,y) to compute the correlation of
> two vectors, which makes sense to me only if x and y are 1-D arrays of
> real numbers,
But what kind of real numbers? IEEE double-precision? Or might you
someday need a correl function that works with ints (e.g., to compute
Spearman's correlation coefficient), or arbitrary-precision floats, or
BCD numbers, or rational numbers, or dimensioned measurements?
As long as your number classes have +, -, *, /, and __float__ (so
math.sqrt works) defined correctly, you don't have to rewrite your
correl code to support them. THAT is the beauty of dynamic typing.
More information about the Python-list