Flying With Python (Strong versus Weak Typing)

Alex Martelli aleax at
Sat Mar 15 09:19:36 CET 2003

Paul Foley wrote:
> On Fri, 14 Mar 2003 12:14:20 GMT, Alex Martelli wrote:
>> I've often daydreamed about having a language where I can offer
>> such hints and compile my programs in at least two ways:
>> -- a debugging mode, where hints let the compiler insert checks
>>    for me and raise warnings or errors when my hints don't match
>>    reality,
>> -- an optimizing mode, where the compiler trusts the hints (at
>>    least to some extent) and uses them to make fast code.
> Why daydream?  You can have that today -- in Python, even!
> Python the CMU Common Lisp compiler, that is :-)

I have elaborated elsewhere as to why I prefer to use Python than
Lisp -- I'm far more productive with Python.  People who find
themselves more productive with Lisp instead would be very well
advised to consider using Lisp, particularly given the maturity
of the compilers available for Lisp.

>> But static typing doesn't come close to making the daydream any
>> closer to true -- often such hints would be things of the form, e.g.:
>>     x > y
>> rather than ones of the form, e.g.:
>>     isinstance(x, y)
>> and why should I use a language that arbitrarily lets me (or even
>> forces me to) offer hints of the latter and not of the former kind?
> I don't know.  In CL you can say that x is of type (integer (y) *)
> [assuming "y" is actually a number] to mean "integer with exclusive
> lower bound y and no upper bound"; i.e., x > y

Extending the concept of "type" in such ways (as Pascal also does,
at least for integers) never stretches far enough (are "integers
divisible by 3" a ``type''?  If no, why should that particular
constraint, x%3 == 0, not be modelable identically to x > y ...?) AND
plays havoc with most other concepts normally related to "type"
(what type is the result of e.g. x/y, x*y, x-y, ... when each of
x and y is of type "integer with bounds A and B"...?).  Not a winner,
in my experience.


More information about the Python-list mailing list