source code size metric: Python and modern C++

David Abrahams dave at boost-consulting.com
Tue Dec 3 11:06:58 EST 2002


Brian Quinlan <brian at sweetapp.com> writes:

> 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);

The type-safe version could easily look like this instead:

   ServerProxy s("http://www.sweetapp.com/cgi-bin/xmlrpc-test/rpc1.py");
   int result = s.call_method<int>("add", 2, 3);
    
That's not too bad.

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

I agree that Python is generally stronger in applications like this
one, but your exaple doesn't demonstrate that very well.

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution



More information about the Python-list mailing list