Type checking in python?

Paul Prescod paul at prescod.net
Tue Jul 18 16:43:49 EDT 2000


Eric Hopper wrote:
> 
> ...
> 
> Oh, yes.  Inheritance by mysteriously coiniciding method names.  How fun.

It has nothing to do with inheritance. We are discussing genericity, not
inheritance. Some languages can only do genericity through inheritance
but this is rare in modern languages.

> Just accepting any old type, and letting it error out when it tries to
> access a non-existent attribute is very confusing for people trying to use
> your code.  Heck, maybe you store away their object, and then call the
> offending method at some random later point.  I bet it'd be a heck of a
> lot of fun to try to trace down why the exception happened then.

It is not a big deal. You aren't the first person to write a large
project in Python. You are of course free to do what you want but I'll
caution you that paranoid type checking is typically a phase that Python
programmers go through. 

You'll notice that the standard library does not use type checking
functions in most places. In a lot of ways the error messages are *less
confusing*. When I get an error message: "read method not defined" then
I know I need to define a "read" method. This is better than having a
hideously complex type inheritance hierarchy in order to enforce nothing
more than that the object needs a read method. That way lies madness:

http://java.sun.com/products/jdk/1.1/docs/api/Package-java.io.html

> Type checking and the scoping rules are the only two problems I have with
> Python so far.  Other than that, it's a wondefrul language.

Type checking is the most major difference between Java and Python. If I
liked everything about Java except its dynamic typing (which is, IMO,
its best feature) I would just use Java like everyone else.
Nevertheless, if you prefer Python with roll-your-own type checking to
Java, more power to you. It's a big tent.

-- 
 Paul Prescod - Not encumbered by corporate consensus
Just how compassionate can a Republican get before he has to leave the 
GOP and join Vegans for Global Justice? ... One moment, George W. Bush
is holding a get-to-know-you meeting with a bunch of gay Republicans.
The next he is holding forth on education or the environment ... It is
enough to make a red-blooded conservative choke on his spotted-owl
drumstick.     - April 29th, Economist




More information about the Python-list mailing list