does lack of type declarations make Python unsafe?

Mark 'Kamikaze' Hughes kamikaze at
Sun Jun 29 10:39:01 CEST 2003

Thu, 19 Jun 2003 09:56:37 GMT, Alex Martelli <aleax at>:
><posted & mailed>
> David Abrahams wrote:
>>       the type of c is a container
> Rather, "c is a container".  Choosing to express "c is a container"
> as "the type of c is the type of a container" is just the kind of
> useless, redundant boilerplate that negatively impacts productivity.
> And in neither C++ nor Java can you express "c is a container", either
> directly or indirectly, except in comments

  That is incorrect for Java, and for most C++ class libraries.

    List c = new ArrayList();
    System.out.println( c instanceof Collection );
    System.out.println( c.size() );
    for(Iterator it = c.iterator(); it.hasNext(); ) {
        System.out.println( );

  Java classes can have interfaces, which may define methods, or may
just be markers for behaviors.  You can create your own completely
custom class that implements Collection, and it can be used anywhere
any of the java.util.* Collections could.  In fact, I find it hard to
understand how anyone could make such an assertion, unless they were
just spouting off without researching it.

  For me, the value of statically-defined types is that I know that
mistyping a method name will show up as an error at compile-time, not at
run-time.  With __slots__ in the new-style classes, at least now Python
can be made to report mistyped field names as errors at run-time instead
of silently assigning to them, which was a maddening type of bug to
find.  I'd prefer to have compile-time checking, but I'm happy enough
with Python's other advantages to live with run-time checking for some

  Python and Java are not diametrically opposed religions that must
fight to the death in jihad, despite the existence of loonies favoring
exactly that.  They solve different problems; sometimes in similar ways,
sometimes not.

  Getting worked up enough about the evils of a type system to post
hundreds of lines of poorly-researched screed complete with Stockholm
Syndrome references, though...  I say this as a friend, there are a lot
of decaffeinated brands on the market today that are just as tasty as
the real thing.

 <a href=""> Mark Hughes </a>
"We remain convinced that this is the best defensive posture to adopt in
order to minimize casualties when the Great Old Ones return from beyond
the stars to eat our brains." -Charlie Stross, _The Concrete Jungle_

More information about the Python-list mailing list