source code size metric: Python and modern C++

Andrew Koenig ark at research.att.com
Sun Dec 1 22:03:05 EST 2002


Pavel> I will be glad to get info/links on this single metric, without
Pavel> going into "who is better" discussion, please. I know the
Pavel> answer is _more_ complicated than single number and am curious
Pavel> on practical experience.

I'm presently trying to implement some pattern-matching algorithms in
C++ (which I know very well) and Python (which I know only moderately
well).  What I'm finding is that the most natural way to express these
particular algorithms in Python is quite a bit different from the most
natural way to express them in C++.  For example, the Python version
of my library makes decisions at run time that the C++ version can
make at compile time by using templates to make type-sensitive
decisions during compilation.  As a result, the C++ version is *much*
faster (between a factor of 10 and 100 in informal tests).

On the other hand, there is one particular decision that I don't want
to have to make at compile time, but I haven't been able to figure out
how to decouple that decision from several others in the C++ version.
In other words, either all of these particular decisions must be at
compile time or they must all be at run time, with corresponding loss
of efficiency.  Moreover, some of the algorithms are most clearly
expressed by using Python generators, which makes the C++ code
substantially more difficult to write and understand.

I expect that eventually, what I learn in implementing each version
of this library will help me improve the other one.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list