[Web-SIG] Client-side API

David Fraser davidf at sjsoft.com
Fri Oct 24 03:53:53 EDT 2003

Simon Willison wrote:

> Bill Janssen wrote:
>> Another possibility would be to mimic the Java 1.4.1 libraries for the
>> Web.  For instance, we could have the "URL" object, which has a method
>> called "open()", which when called gives you a "Connection", which can
>> be of subtype "HTTPConnection", "FTPConnection", etc.  Call the
>> "create_request()" method on that "Connection" to get a new Request
>> instance, use "set_header()", "set_cookie()", "set_body()", etc., then
>> call the "send()" method, getting back a ReplyPromise instance, which
>> can then be interrogated periodically to get a Reply instance, etc.
> Ugh. One of the things I love about Python is that unlike Java it 
> doesn't force you to have horribly verbose interfaces with dozens of 
> different classes. A URL is a string, file-like-objects are 
> file-like-objects and most of the modules in the standard library only 
> make you deal with one or two classes and a few useful utility methods.
> I'm all for replicating the capabilities of Java libraries (if they 
> have a good bunch of features) but replicating the exact APIs seems to 
> me like a lost opportunity to take advantage of Python's more 
> expressive syntax.

Absolutely. We need to be using attributes rather than method accesses, 
and dictionary/list-derived classes where sensible and possible.
(We shouldn't imitate dictionaries by mimicing methods, and we should 
use the new-style classes if we need to extend them)


More information about the Web-SIG mailing list