C and Python

John Machin sjmachin at lexicon.net
Mon Apr 8 18:06:47 EDT 2002


Philippe Faes <Philippe.Faes at rug.ac.be> wrote in message news:<3CB19A7E.4090600 at rug.ac.be>...
> I want to use python for quick prototyping and convert to C/C++ later on.
> Suppose I write some modules (say 2) in python that call eachothers 
> functions.

Short answer: Don't do that.

Consider carefully why you think that the modules (no matter in what
language they are written) should call each other's functions. To me
this is prima facie evidence that some functions are in the wrong
module(s).

When you have such a loop in your call graph, you will be forced
*forever* to consider all the modules in the loop as one module,
because they are interdependent. If they *are* conceptually one
module, then smash them together now. Otherwise, untangle them now.

Try to arrange your modules in layers; for example, "appliance"
modules call "sub-assembly" modules which call "nuts/bolts/tools"
modules.

> Then I port one module to C/C++ and later the second module. 
> In the meanwhile I will want my hybrid project (python-C) to work.
> 
> My question:
> Does any of this already exist?

If you mean a collection of macros or some other band-aid for
supporting switching between C calls and Python calls, I doubt it.
Prevention is better than cure.

> Any hints?

You may have already been planning this: try to write or at least
design an application which makes substantial use of your modules,
while they are still in the Python stage. This would help expose any
kinks in your APIs.

HTH,
John



More information about the Python-list mailing list