Python from Wise Guy's Viewpoint

Pascal Costanza costanza at web.de
Tue Oct 28 18:26:47 EST 2003


Matthias Blume wrote:

> Pascal Costanza <costanza at web.de> writes:

>>I think that Neelakantan has better examples for programs that are
>>possible to write with a statically typed language, but not with
>>dynamically typed ones. (Not 100% sure yet, though.)
> 
> There are no such programs, obviously.  You can always translate a
> statically typed program into a dynamically typed one (and vice
> versa).

No, for christ's sake! There are dynamically typed programs that you 
cannot translate into statically typed ones!

As soon as you add full-fledged runtime metaprogramming to a language, 
and write a program that uses it, you cannot statically type check this 
anymore, by definition, because you cannot statically determine anymore 
in what ways such a program would change during its lifetime!

And don't tell me that "in 99% of all cases, you don't need this". This 
just isn't true. And even if it were true, it wouldn't matter!

If there would only be _one_ useful program on earth that someone cared 
about that would make use of runtime metaprogramming, this would make my 
statement true that static typing decreases expressive power in possibly 
serious ways. And there are definitely lots of them out there!

> The advantage (as far as I am concerned) of the statically typed
> program is in the guarantees that it provides:  If I write
> 
>    fun foo x = ...
> 
> and x is declared or inferred to be of type t, then I never again have
> to worry about what happens should someone pass a non-t to foo
> because that simply cannot happen.  This all by itself is useful, but
> it gets even more useful if t is an abstract type so that I have full
> control over how and where t values are generated.
> 
> This sort of thing is most useful when designing libraries because in
> this case you don't know yet (who will call foo and how (and you might
> in fact never know). But you do know that whoever it is and however he
> does it, he must pass a value of type t.

Yes, these things are all obvious. But these are not examples for an 
increase of expressive power! These are only examples of _restricting_ 
the set of potentially useful programs! How hard is this to understand?

You _want_ this restriction. Why don't you _admit_ that it is a restriction?


Pascal





More information about the Python-list mailing list