Programming in Python with a view to extending in C at a later date.

Scott David Daniels Scott.Daniels at Acm.Org
Mon Apr 20 17:56:37 EDT 2009


dug.armadale at googlemail.com wrote:
> Say you set out to program in Python knowing that you will be
> converting parts of it into C ( or maybe C++) at a later date, but you
> do not know which parts.
> 
> Can you give any general Python structure / syntax advice that if
> implemented from the start, will make this future task less painful.
> In addition, advice that will make this easier for automatic tools
> will be good too.

The best advice I have is, "Ignore the conversion task, and get your
algorithms and data structures right.  Once you have that, _measure_
where your inner loop is and rethink.

When you've identified your inner loop(s), and only then, isolate that
code and shift its style to a more static style (essentially testing
your C/C++ algorithms in Python).

Now you can either go for the translation or use something like Cython
or Pyrex to see if automatic translation will be good enough.
This technique takes advantage of the fact that trying several different 
algorithms will be much easier in Python than in C or C++.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list