source code size metric: Python and modern C++

Brian Quinlan brian at sweetapp.com
Tue Dec 3 01:08:03 EST 2002


6) Dynamic typing (saves a lot of proxying and crude
   introspection mechanisms)

7) Dynamic runtime (let's you perform time-saving magic
   when you really need to)

Has anyone done any RPC programming in C/C++? I'll use XML-RPC as an
example. In Python, making an XML-RPC call is as simple as this:

>>> from xmlrpclib import ServerProxy
>>> s =
ServerProxy('http://www.sweetapp.com/cgi-bin/xmlrpc-test/rpc1.py')
>>> s.add(2,3)
5

Python has no previous knowledge of the methods available on the server
or what types they accept. In C/C++, you would have to do something like
this:

ServerProxy s("http://www.sweetapp.com/cgi-bin/xmlrpc-test/rpc1.py");
int result;

s.callMethod("add", "ii", 2, 3).parse("i", &result);

Of course this code is completely type unsafe - screwing up a format
character may result in a crash. Here is a type safe version:

ServerProxy s("http://www.sweetapp.com/cgi-bin/xmlrpc-test/rpc1.py");
Call call = s.newCall("add");
call.addArg(2);
call.addArg(3);
call.make().parse(&result);

And the complexity of marshalling/unmarshalling increases as the
complexity of the types involved increases. Also, the complexity
increases if multiple return types are expected. 

The Python version is simpler because type information does not have to
be specified at compile time and because mechanisms such as getattr can
be used to implement attributes on the fly.

Cheers,
Brian 





More information about the Python-list mailing list