Experiences converting Python to C++

Courageous jkraska1 at san.rr.com
Fri Aug 17 13:29:20 EDT 2001


>I have some such experience, but never on such a scale (I think
>the 10K lines of Python will translate to roughly 80K-100K lines of
>C++, ....

The last time I ported Python to C++, I created a special class library
for maintaining some kinds of Python semantics in C++. For example.

SymbolTable table = new SymbolTable();

Symbol symbol1 = table->Intern("this is a test");
Symbol symbol2 = table->Intern("this is a test");

if (symbol1==symbol2) ...

-------------

Symbol does not have an overloaded equals operator. Rather, the
symbol table arranges all lexigraphically identical strings in the same
symbol table to have the same address. This allows you to use symbols
in hash tables without having to element-wise compare their string bodies
on collisions, amongst other things. Also, strcmp() isn't needed.

There are also some convenience functions. For example:

Symbol symbol3 = table->VaIntern("this is a test, number %d", 3);

-----------

Discounting the library itself, code bloat was really only about ~200%.

The key to getting this right is making sure that you can TRANSLITERATE
your Python to C++. Translation is not good enough.

C//




More information about the Python-list mailing list