beginner question: extending python types

Alex Martelli aleax at aleax.it
Mon May 13 18:21:18 EDT 2002


Uwe Mayer wrote:
        ...
> I want to force certain parameters of methods to be of a specific type,

If you really want this, you chose the wrong language.  Most languages
devote substantial amounts of mechanism to such 'bondage' issues.

Python distinguishes itself from by far most languages by NOT doing
this, which is from where much of its extra power comes -- from where
much of the incredible productivity boost it gives programmers comes.

But if you want to do this, in Python you're "fighting city hall", going
against the grain of the language.  Choose another.  I recommend
Haskell, whose typing system is really wonderful.  You'll get compile
time checking of your types, exactly as strong or weak as you want
it to be.  Choosing Python and then going typechecking will reduce
or countermand Python's productivity gain AND still never get as far
nor as deep as a statically-checking language would -- a _good_
one, at least (forget the mishmash mis-called a "type system" in
such languages as C++ or Java -- go for Haskell, or ML in some
variant or other).

I don't think you _need_ this typechecking, though I can't know your
situation enough to be sure.  But whether you need it or not, if you're
going to use it, drop Python in favour of some statically-typechecked
functional language with a good typesystem.  This is my advice.


Alex




More information about the Python-list mailing list