Optional Static Typing

John Roth newsgroups at jhrothjr.com
Thu Dec 23 12:06:55 EST 2004


<bearophileHUGS at lycos.com> wrote in message 
news:1103795375.843649.286620 at c13g2000cwb.googlegroups.com...
> Adding Optional Static Typing to Python looks like a quite complex
> thing, but useful too:
> http://www.artima.com/weblogs/viewpost.jsp?thread=85551

One of the comments on Artima asks a rather profound
question: static typing is an answer. What's the question?
(That's a paraphrase.)

The answer that everyone seems to give is that it
prevents errors and clarifies the program.

I'm not convinced that it's all that effective at either objective.
My viewpoint on this is
that of someone who generally uses test first programming
(as in Test Driven Development or Extreme Programming).
Many of the supposed advantages simply aren't there
when you go to the discipline of writing a test and then
writing exactly the code needed to make the test pass, and
not one keystroke more.

Most of the kinds of error that static typing is supposed
to catch simply don't persist for more than a minute when
you do test driven development.

This isn't to say TDD is the be-all and end-all of
correctness. Formal methods and formal inspections
both have very good reputations. In fact, the technique
with the best reputation is embodied in a sign that was
on the wall of every office of the old IBM: Think!

So let's look a bit deeper. As far as I remember, static
typing came out of the formal methods work in the '70s
by people like Djikstra, Hoar and Wirth (to name only
a few.) The thing is, if you properly use the formal program
derivation methods they advocated, then you don't need
it: your program will be as correct as it's possible to get
short of your being promoted to godhood.

So the conclusion here is that static typing is an attempt
to make programming safe for people that shouldn't be
programming in the first place. This may sound a bit
cynical, but most real uber-programmers have either
Lisp or Smalltalk in their backgrounds, and
frequently both one. Neither of those languages
have static typing, and they simply don't need it.

So if the problem is reducing errors, then maybe
we should be working on the places where errors
show up.

Another point that's sometimes raised is that it's
useful to provide type information via reflection.
I used to think that was a valid concern until I
started work on PyFit. I had to put a rather
simplistic metadata facility into the program to
substitute for not having type information, and
I found that it was incredibly useful for other
things that you can't get from reflection on
type data.

John Roth

> Bear hugs,
> bearophile
> 




More information about the Python-list mailing list