Python complements C++ for productivity

Don Bashford bashxxxford at nospam.scripps.edu
Tue Jun 20 17:00:39 EDT 2000


I've been using C++ for about 10 years, and Python less than a year.
I recently had the experience of implementing an algorithm for
Delaunay triangulation in both Python and C++.  I was working from my
reading of someone's Ph.D. thesis that had parts of the algorithm in
pseudo-code, and part in English.  

I started out in Python.  The work was pleasant and went fairly
quickly.  It was pleasing that a lot of the Python I wrote ended up
looking very close to the pseudo-code in the thesis.  The interpreted
nature of Python was very helpful, since it made it easier to inspect
results as I went along.  I also benefited from a Python graphics
package written by a colleague that hepled me visualize what the
algorithm was doing.  I think in the early phases, development in
Python was faster than it would have been in C++.

But the resulting code was slow---about 100 times slower than the
thesis author's C code.  I started re-implementing in C++.  The
similarity of the basic "class" ideas in the two languages made the
re-write very easy and fast.  In some cases, I just dropped the Python
code into the C++ file and edited it.   In the translation process,
the stricter type rules of C++ helped me find some bugs that I might
never have found in the Python version, and it also resulted in
improved design.

The only real unpleasentness in the whole process was when I had my
implementation partly in Python (higher level) and partly in C++
(lower, more number crunching levels).  Then I was using SWIG to
"wrap" the C++ parts for use from Python, but getting proper handling
of translations like Python lists to C++ containers was quite a pain
(although I learned a lot about SWIG typemaps in the process).

In short, I found Python to be a great prototyping language, with
pretty easy movement to C++, which is a great language when you want
strict type checking, data hiding and performance.



More information about the Python-list mailing list