[Types-sig] Why I don't like static types in Python

Tim Peters tim_one@email.msn.com
Sun, 29 Nov 1998 23:13:32 -0500


[Justus Pendleton]
> Unfortunately (the main reason I really am bothering to argue
> against static typing at all) I think that this viewpoint misses
> the fact that most people who start programming in Python have been
> programming in other languages.  They bring the baggage of those
> languages with them.

You may be able to score points where it counts by reminding Guido how well
adding a convenient little half-baked lambda turned out <0.9 wink>.

> When DoD Ada programmers start writing C++ code they wonder why
> C++ can't do bounds checking for arrays.

OTOH, pressures like that made Stroustrup add inlined methods to C++ so
people could write their own bounds-checking array classes that run at least
as fast as Ada's builtin checked arrays.

> When Visual Basic programmers start writing Java code they wonder
> why there is no 'Variant' class.

I figure they wonder more what sick delusion caused Java to claim that the
AWT was a usable GUI substrate <0.7 wink>.

> Since most of the languages out there (especially the popular ones)
> use static typing, people will use it in Python regardless of whether
> they need to.  When they learned C they were taught they needed to give
> a type to every variable....and when they write Python code they will
> continue to give it a type without thinking of whether it really needs
> to be there.

And the harm in that is what?  It would be hard to argue it's *bad* that C
has declarations, or that it's bad to declare things.  What's the worst that
can come of it?  Some extra typing?  The chance that one routine in a dozen
could have been used in a more general way if the declarations didn't
prevent it?  Those are the only two I can think of, and they're not much of
a fright.

If a casual Python user nevers goes beyond that, I don't mind; and if
they're happy too because it lets them do more what they're used to doing, I
don't mind that either.

If they want to go on from that, any declaration system for Python will most
likely include higher-level abstractions like Sequence and Number, at which
point the potential polymorphism lost to explicit declarations becomes more
academic than real.

And if they want to go on from that too, declarations remain optional.

Almost everyone who comes to Python writes stuff like

    for i in range(len(list)):
        print list[i]

at first.  After you point out a few times that they can do

    for thing in list:
        print thing

instead, they eagerly switch styles -- because it's clearer, runs faster,
and is less error-prone.  Telling them they should stop using declarations
because it's more fun to get runtime errors is likely a harder sell <wink --
but why else "should they" stop declaring things?>.

unlike-say-implicit-conversions-declarations-aren't-
    inherently-evil-ly y'rs  - tim