does lack of type declarations make Python unsafe?
gmduncan at netspace.net.au
Mon Jun 16 16:53:56 CEST 2003
Alex Martelli wrote:
[ lots deleted ]
>>>Calling functions with invalid arguments is one of the commonest
>>Debatable. Not true in my experience.
I suspect this assertion relates to juxtaposing args, not so
much the values thereof. Obviously passing bad values to a function
is a crime we have all committed - at least it's one I admit to ;)
In the pre-ANSI-C days, I did this occasionally - and even thereafter
coz if multiple args had the same type (int?), the function definition
wouldn't help if one put the args out of order.
> Pretty true in my own experience, for a suitably generalized definition
- Gary (definitely a proponent of dynamism )
> of "functions" that includes operators and other callables. However,
> the reasons the arguments are "invalid" are more often connected to the
> *values* that those arguments take at runtime, rather than to the types
Hmm, I'll have to think about that ;)
> of those arguments (which might be checkable at compile time if one
> used a statically-typed language), therefore this is not an argument
> in favour of static type-checking. E.g., indexing blah[bloh] with an
> invalid index value computed in variable bloh (invalid with respect
> to the set of indices that container blah can accept) is, alas, far
> from rare; but it's not a type-checking issue, and rarely will a
> compiler be able to deduce reliably that the value of bloh as run-time
> computed is going to be invalid. Thus, runtime checks are needed here
> (Java does them, Python does them, C++ may or may not do them) -- AND
> unit-tests that you can trust to tickle any bugs that might be there...
More information about the Python-list