not safe at all

Dennis Roark denro at earthlink.net
Fri Jul 13 12:00:22 EDT 2001


I appreciate those who replied, particularly Nick's
informative reply.  I would still argue that "dynamic"
typing is a weaker and less safe sort of typing than the
static typing of C++.  Nick brings up the C++ example of
using pointers to void and then casting them as needed or
recasting them to allow the variable to point to different
objects not involved in an inheritance relationship.  But
C++ is also often criticized for this because void pointers
do allow for unsafe coding, relaxation of type safety and
should be avoided if possible.

Python is an attractive language.  But for a large program I
would still rather be forced to declare the name of a
variable (and its type) rather than risk misspelling or
misuse 500 lines later in the program.  My original note was
not intended to be an indictment of Python, but only to
bring up some reasons that for me make more strongly typed
languages like C++ or Object Pascal better at coding very
large projects.

9nick9m at alum.mit.edu (Nick Mathewson) wrote:

>On Fri, 13 Jul 2001 07:32:28 GMT, Dennis Roark <denro at earthlink.net> wrote:
>>For amusement, run this little script which demonstrates a
>>near ultimate in the lack of type safety in the language.
>>(Perhaps there is a bit of type safety in that you can't do
>>this:  4 + "one") But look at what you can do in the
>>following script:
>>
>>x = 3
>>x = x + 2
>>print "x =", x
>>x = "now I'm a string"
>>print x
>>x = [ 5, x ]
>>print "and now a list:", x
>>
>>If you don't believe it, run it.
>
>I believe it, but it doesn't demonstrate a thing about type safety.
>You've just discovered dynamic typing.  You see, your implied view of
>typing seems to come from a statically typed language, where every
>*variable* has a type of its own.
>
>In Python, types are associated with *objects*, not with *variables*.
>IOW, all variables are of the same type: reference-to-object.  
>...
>
>Or even C++:
>  // Watch out! My C++ is rusty.
>  class Integer { int val; 
>                  public: Integer(int v) : val(v) {}
>                  operator int() { return val; } }
>  void* x = new Integer(3);
>  x = new Integer(2 + *(Integer*)x);
>...
---------------------------------
Dennis Roark
Dept. of Computer Science
University of Sioux Falls

Starting Points:  http://home.earthlink.net/~denro
---------------------------------



More information about the Python-list mailing list