[Types-sig] Re: Types-SIG digest, Vol 1 #13 - 2 msgs

Tim Peters tim_one@email.msn.com
Mon, 30 Nov 1998 23:30:09 -0500

[Dominic Binks]
> ...
> I would hazard a guess that may be as much as 90% of Python code
> is regularly type following.

I'd bet that's on the high side of the truth.  From the Walker/Griswold
paper I  posted a link to over the weekend,

    An empirical study using the type inference system described here
    was conducted on a large number of Icon programs written by many
    different authors for a wide variety of applications. The results,
    which are conservative, show a range of type consistency from about
    60 to 100%, with an average of about 80%. That is, on the average,
    the operands of about 80% of the operators in these programs always
    have the same type.

It's likely lower in Python, because (I believe) Python programmers write
more polymorphic functions than do Icon programmers.

But while that's of great interest to a type inferencing system, it's of no
particular interest to those seeking static declarations:  if you want to
use declarations, you'll have to write 100% type-consistent code whenever
declared entities are involved -- and known to be type-consistent at
compile-time.  I.e., it's a tradeoff (as if that weren't apparent from the
first instant <wink>).

> ...
> There are lots of parts of Python that pose problems for type systems.
> The following example is just one (that I don't think has been given
> before, but I may be wrong in that)
> 	def f(x):
> 		if type(x) == StringType:
> 			...
> 		elif type(x) == IntType:
> 			...
> Then x can legitimately take either an Int or a String, which is
> possibly quite hard to code in a type system.

You can view it as a union of basic types, or as an atomic Strint type --
keping track of either view is easy.  If you try to pass one of those beasts
to something declared as requiring an int, you should die at compile time.
That is, there's no problem here, except for whiners insisting they need to
have it both ways at once.  I ridicule them in advance so there will be no
need for unpleasantness later <wink>.

they-can-declare-everything-"object"-ly y'rs  - tim