Experiences converting Python to C++

Terry Reedy tjreedy at home.com
Sat Aug 18 11:56:33 EDT 2001


 "Henrik Ekelund" <henrik_ekelund at yahoo.com> wrote in message
 news:f583a35.0108170452.1b3eca85 at posting.google.com...
 > We have to convert a large system (10000 lines) written in Python
to
 > C++. Does anybody have experience with doing an actual conversion
of a
 > working Python prototype to C++? We will probably have to offer the
 > work at a fixed price, so how many hours does it take to convert X
 > lines of Python code to C++? Are there any pitfalls?

You did not specify either a definition of 'convert' or the purpose
thereof.

If the only purpose is to provide a 'pure' C++ program, then a frozen
version of the Python program, which treats PyCode as text strings,
qualifies.  Feed it to a C++ compiler and the output will be a unitary
executable for the particular platform.  This is similar to a database
program that interprets SQL similarly embedded in text strings.

For some speedup, one could convert Python code into the equivalent
API calls. Again, anything a C++ compiler can compile into a working
executable is legal C++ code.   Python's builtin types comprise as
legitimate a library as anything else.  Why replace Guido's rendition
of extensible arrays, dictionaries, reference counting, etc, with
someone else's?  The main exception would be to unbox numbers and
arithmethic thereon where it is certain that Python's polymorphism is
not being used.

If the requirement to to use only a subset of C++ (classes but no
structs, no 'extern C', etc), then more needs to be done (and paid
for).

Terry J. Reedy





More information about the Python-list mailing list