not safe at all

Christian Tanzer tanzer at swing.co.at
Sat Jul 14 09:33:02 EDT 2001


Dennis Roark <denro at earthlink.net> wrote:

> 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.

I think you are still missing some important facts about typing
systems. There are two dimensions: static vs. dynamic and weak vs.
strong.

Now, C++'s typing is moderately (some call it weak) strong and static.
Void pointers are not necessary to get into trouble with C++'s type
system. Type casts and implicit type conversions are two likely
gotchas. And when typing fails in a language like C++, all bets are
off. 

Python's typing is strong and dynamic. Wrong interpretation of bits
just doesn't happen. And if you try to use an object incorrectly you
will get an exception. Exceptions are safe unless you choose to ignore
them in your exception handlers.

> 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.

Strong typing is not a panacea for bad designs. Refactoring will do
better. 

If you really need strong static typing, look at languages like Eiffel
or Ada. Both C++ and Object Pascal are broken in comparison.

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list