05 March 2006

Of Python and C++

I did some experimenting today with both Boost.Python and SWIG, and SWIG will be the wrapper of choice, at least for now. Boost might be better for some things, but the whole installation and configuration step was a huge hassle and ultimately I didn't get it to work properly on my setup. SWIG on the other was usable right away, and after a brief read through the basic documentation, I had a working version of my C++ extension.

Python has proved to be an excellent prototyping tool for the C++ extension. I'm currently developing the extension in tandem with a pure Python version so that, whenever I'm about to implement a new class, I add it to the pure Python version first and test it. This way I can verify all architectural and algorithmical ideas before writing them in C++. I'm also writing the prototype in "C++ style" so that each dynamically created object has .new() and .delete() methods (and my tests track memory allocation issues), and I use 'this' instead of 'self' etc. This makes writing the C++ code based on the Python prototype very straightforward and fast. So, even though I'm pretty much writing all the code twice, I think I'm still making faster progress compared to trying to write the whole thing directly in C++.


Anonymous foot said...

Yes! Python prototyping really is stunning. I prototyped all my comp. uni assignment in python last year before 'porting' them into C++/Java; it was often almost straight line for line. It's just such a 'RAD' language, feel so productive and quick.

One of these was a 3D file viewer (OFF), python/pyopengl implementation only took a day or to, having a quick edit-test turnaround is so valuable. Once you get out the kinks you can drop it straight down to C++... well, almost, if you could use class methods as GLUT callbacks. >_<

09 March, 2006 13:50  

Post a Comment

Links to this post:

Create a Link

<< Home