does lack of type declarations make Python unsafe?
tjreedy at udel.edu
Mon Jun 16 23:13:40 CEST 2003
"David Abrahams" <dave at boost-consulting.com> wrote in message
news:uwufmko7g.fsf at boost-consulting.com...
> I find that static typing makes a big difference for two things:
> 1. Readability. It really helps to have names introduced with a
> type or a type constraint which expresses what kind of thing
Perhaps true, especially for C/C++, but given polymorphic operations
and the absence of an extensible hierachical type system, the
enevitable cost is excluding valid argument values. By fixing both
external interface/behavior and internal structure/implementation,
declaring types fixes too much. Preprocessor macros, with *untyped*
parameters, (like #define max(num1,num2) ...) are an homage to the
virtue of generic programming.
The other problem, which I discussed in another post to this thread,
is that current static typing systems, besides being too narrow, in
excluding valid imputs (given Python's object and operation system),
are also too broad in including invalid values. They often do not
adequately express 'what kind of thing' something is because the only
choice is *too* inclusive.
Besides the above, much Python code is, for me, pretty
self-explanatory as to types. Is 'int i', etc, really clearer than
'i=0', etc. Arithmetic expressions usually define the involved
variables as numbers. 'For item in seq' defines seq as a sequence of
some type, specifics usually not too important. And so on.
And of course, one can give each Python variable a one-line
definition, with a type name even, of the same sort I often did with C
variables. Just move the comment start symbol leftward to the margin
Terry J. Reedy
More information about the Python-list