Type checking in python?

Eric Hopper hopper at omnifarious.mn.org
Tue Jul 18 19:51:55 EDT 2000


In article <3974C185.E39E082E at prescod.net>, Paul Prescod
<paul at prescod.net> wrote:
> 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.

OK, genericity.  I call generic programming 'inheritance for the lazy'. 
It's the thing I most dislike about STL.  No requirement at all the you
specify your interface anywhere, or make a statement about your class
conforming to it.  It just mysteriously calls these methods that have
these special names and hopes for the best.

Of the modern languages, the one I can think of right offhand is Java. 
And that's something I actually like about it.

> 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.

	So, what class do you need to define a read method for?  Where did that
object get passed in?  What if the read method is only called in some odd
circumstance that manages to excape anyone's notice for years?

> 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

This doesn't look too bad, though I think it's a little ill-designed.

> 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.

I prefer almost anything to Java because you can't get a standard Java
implementation anywhere.  Sun's got the standard all locked up.

I also dislike the incredibly heavy runtime environment that Java comes
with, and the fact that it's missing any I/O multiplexing mechanism, and
so you're forced to have threads.  Have you ever tried to write something
that dealt with 500 clients using a reader and writer thread for each?  I
thought not.

Anyway, this isn't a Java bashing forum.  :-)

--
Eric Hopper (hopper at omnifarious.mn.org)  (http://www.omnifarious.org/~hopper)




More information about the Python-list mailing list