Matt's Mind

Wednesday, September 08, 2004

More on dynamically typed languages

Check this Python API document for a mail-processing library:
class UnixMailbox( fp[, factory]) Access to a classic Unix-style mailbox, where all messages are contained in a single file and separated by "From "(a.k.a. "From_") lines. The file object fp points to the mailbox file. The optional factory parameter is a callable that should create new message objects. factory is called with one argument, fp by the next() method of the mailbox object. The default is the rfc822.Message class (see the rfc822 module - and the note below).
This is a classic example of why dynamic typing makes it harder to understand an API. So you need a "fp" to create a UnixMailbox instance. Que? "The file object fp points to the mailbox file" - oh, I see, that makes it much clearer. Now I can go and grep for "file" and see that class might actually do the job here. Is it a file, filename, something that implements open () and read (), any of the above?

With a statically typed language it would be "class UnixMailbox (File file)", with a link to the File class so I can work out how I can make one that fits.


Post a Comment

<< Home