source code size metric: Python and modern C++

Christian Tanzer tanzer at swing.co.at
Mon Dec 2 03:26:03 EST 2002


pavel_vozenilek at yahoo.co.uk (Pavel Vozenilek) wrote:

> Guido van Rossum in his article
> (http://www.python.org/doc/essays/comparisons.html) compares C++ and
> Python and finds Python source often 5-10 smaller than equivalent C++.
>
> Has somebody experience what the situation is for modern C++ (the one
> with STL, Boost, etc.)? I am interested in larger systems handling
> complex data structures.

Class libraries don't change the picture (the most an existing C++
class library can do for you is change the offset).

IMHO, the biggest difference between C++ and Python is boilerplate. In
Python, you can add mechanisms like persistence, introspection, etc.
to a class hierarchy without changing the existing classes.
OTOH, in C++ you have to add (often very repetitive) code to every
single class.

Another huge advantage of Python is its ability to do things at
run-time. In principle, this might be bad for performance. In
practice, it often isn't (and when it is, you optimize the hot spot
and still are finished ahead of somebody implementing in C++).

I recently had to look at the design and implementation of a C++
application I wrote some years ago and I couldn't believe how I've
ever been able to put up with all the annoyances C++ throws at you.

YMMV,

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list