does lack of type declarations make Python unsafe?

Brandon Corfman bcorfman at amsaa.army.mil
Thu Jun 19 08:29:12 EDT 2003


Steven Taschuk wrote:
> 
> However, I suspect that the question that's actually frequently
> asked is something like:
> 
>     "I'm used to C/C++/Java, and I rely on the compiler using the
>     variable declarations to tell me when I've made a type error or
>     mistyped a name.  How can I avoid these kinds of bugs in Python?"
> 
OK, that's clearer. I can give that a shot.

> 
>>I don't see what there is to fear in this regard either. Lisp/Dylan have 
>>done optional typing and range checking, and it improves safety as well 
>>as performance -- without changing the character of the languages or how 
>>they're used. I don't see why Python would be any different.
> 
> Sounds fine to me.  Want to write the patch?  :)
> 
Ha, I think you're trying to trick me. :D Maybe I should start with a 
PEP. I suspect I'll have to catch up on all those types-sig messages first.
> 
>>[...] The multiple variable assignment and 
>>multiple return values in Python allows for programming without 
>>side-effects. [...]
> 
> 
> But assignment is the quintessential side-effecty operation, nyet?
> 
Yes, of course, but to quote Paul Graham,
"Having functional programming as an ideal doesn’t imply that programs 
should never have side effects.It just means that they should have no 
more than necessary." [1]

Localizing side effects to passed-in & return values only makes it much 
easier to track down bugs, IMO. If you have too many member 
variables/globals holding state for your functions, then it becomes a 
real problem to setup unit tests or to quickly evaluate success from the 
command prompt.

Best regards,
Brandon

[1] "On Lisp", Paul Graham, p. 31. http://www.paulgraham.com/onlisp.html





More information about the Python-list mailing list