Separating template C++ code from Python code?

Asked by Jamie Kirkpatrick

I spent some time yesterday reading and modifying pybindgen to get my head around the way it works. Overall the library is very well implemented (I'm coming from SWIG so you can imagine the pain I'm used to) and I would love to start using it (once I iron out how to produce fully compatible interfaces to conform to my current SWIG'd implementation), but one thing that stuck out as vastly lowering the readability of the code was the fact that the C++ code generation was interspersed in the Python code directly.

I've done quite a bit of C++ code generation in the last few years and I have found over time that it really helps the readability and maintenence of the code if the template code can be somehow seperated into its own area. I have solved this in the past by relying on a template engine (I used Mako) to seperate "presentation" from business logic: you could just as easily separate out Python template strings and not rely on any external module.

I'd love to see this happen in this project because I do think you would end up with vastly cleaner code. Any thoughts? Again, if help were needed I would be willing to lend a hand.

Question information

Language:
English Edit question
Status:
Answered
For:
PyBindGen Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Gustavo Carneiro (gjc) said :
#1

PyBindGen started out nice and simple, but has been evolving to considerable complexity, and the python/C mix is low on sophistication (which is not bad) but makes some things harder to read or write.

I am not experienced in any template engine, so I don't understand yet how well a template engine could replace our mixed python/C code. In any case, we'd need a template engine that could be easily embedded in PyBindGen; adding an external dependency to PBG is to be avoided..

Mako looks interesting (both syntax and it compresses to only 40K tar.bz2)... just don't expect any template engine to make all python/C mixing to disappear, it will only reduce it...

Can you help with this problem?

Provide an answer of your own, or ask Jamie Kirkpatrick for more information if necessary.

To post a message you must log in.