source code size metric: Python and modern C++

Brian Quinlan brian at sweetapp.com
Thu Dec 5 04:30:12 EST 2002


Duncan Grisby wrote:
> I disagree. You are going to have to tell people writing clients to
> your services what their interfaces are, otherwise they won't be able
> to understand how to use them. Given that you've got to do that, and
> you've got to make sure you are unambiguous in your descriptions, a
> formal interface definition language is a huge benefit.

I disagree with the need for type descriptions being present when
describing an interface. The Python documentation often does not
formally present the argument and return types but people seem to get
along fine.

Also, IDL alone is not sufficient because it need not provide a semantic
description and any constraints more fine than type e.g.

rotate(theta)

0 <= theta <= 2* pi

> I'm not convinced that that kind of ability is so useful when you
> think about real functions in real applications, of the level suitable
> for use in an RPC system. I think it's useful for low-level functions
> like adding things, and generic algorithms like sorting, but much less
> useful for higher level things.

Why would dynamic typing not be useful in an RPC system if it is useful
in other applications? Or is dynamic typing not useful in general?
  
> Of course, the same issue is there in normal Python programs. In that
> case, making sure functions are called with the right argument types
> is purely a debugging issue, and it's usually easy to look at a
> function to see what it's expecting. In a distributed environment, you
> don't have so much control over the clients, and clients may be
> actively malicious. Any help the environment can provide in protecting
> you from unexpected inputs is a good thing.

Assuming that you are correct and I really want type checking in my
Python RPC server, I can accomplish that in two ways:

1.  I can just add an assert statement e.g.
    assert isinstance(x, int) and isinstance(y, float)

2.  For the newer XML-based web services, I can use any XML validation
    scheme that I want (e.g. DTD, Schema, Relax NG). And my clients can 
    use that validation system as well (if they want).

But notice that Python gives you the flexibility without forcing you to
jump through hoops. The worst case in Python forces you do no more work
than in C++.

But can't you convince yourself that Python has an advantage in this
area though a simple thought experiment:

Imagine writing a simple XML-RPC client that searches for Python
articles on the O'Reilly Meerkat network and prints their titles. Now
imagine doing the same using an IDL-based RPC interface in a statically
typed language. Do you really think that the IDL technique would
actually get you to working code faster.

For fun, I actually did the Python XML-RPC version:

from xmlrpclib import Server
s = Server('http://www.oreillynet.com/meerkat/xml-rpc/server.php')
for i in s.meerkat.getItems({'search' : '[Pp]ython'}): print i['title']

Reading the documentation took about 5 minutes.
Implementing/testing/debugging the code took 30 seconds (I typed the
code directly into the shell). 

Cheers,
Brian 





More information about the Python-list mailing list