Reddit - r/programming

The story of Pybinding - a python wrapper around C++...

The Problem

The story starts with a common problem: Python is a fantastic language for rapid prototyping, data analysis, and orchestrating complex tasks. However, when it comes to raw computational speed, especially for number-crunching or highly parallelized operations, it can fall short. C++ and other compiled languages, on the other hand, excel in these areas.

The question was: how do you get the best of both worlds? How do you write the performance-critical parts of your application in C++ while still enjoying the development speed and ecosystem of Python?

The Solution

The answer was to create a "binding" – a bridge that allows Python to call C++ code as if it were native Python.

Early efforts in this space, such as Boost.Python, were powerful but often came with a steep learning curve and significant compilation overhead. They were a bit like using a sledgehammer to crack a nut – effective, but perhaps a bit unwieldy for many use cases.

A Glimpse of the Result

Have a look at how neat the Python code looks; however, the actual job is done by the background C++:

import libfoodfactory

biscuit = libfoodfactory.make_food("bi")
print(biscuit.get_name())

chocolate = libfoodfactory.make_food("ch")
print(chocolate.get_name())

Do you like the story? Click on the link and learn about pyBinding - a glue to stitch C++ and Python.

Comments

No comments yet. Start the discussion.