When you’re on a good thing … keep it going! So our webinar next week after our previous webinars means three (at least!) is a charm with Antony, Rainer and myself (Richard Hickling) presenting the use of C++ with Python.

The fact that C++ and Python are used together might well be surprising for modern programmers in both languages. They are so very different and are used in very different ways. It’s not obvious that they should be combined. How has it come about?

My analysis is that it is mostly the result of history: Python was developed during one of the renaissance periods for C++ (there have been several). Guido van Rossum (the inventor of Python) was clearly influenced by C++ - that can be seen with its object-oriented model (classes, multiple inheritance etc). But it was also the time when Perl ruled the world as a scripting language. Initially, most people saw it as “a better Perl”.

That’s the context in which I first met it. I was in a project that mixed Perl with C++. It was a mess. The joke was that Perl is a “write only language” - in that it is impossible to understand Perl source code of any complexity.

Someone probably suggested Python to me on the basis of my Perl woes - I can’t remember. But when I first used it I was amazed: I wrote a few useful lines - and it just worked! First time! That’s never how it went with Perl (or C++).

When I introduced to the managers on the project - and for the next few years back in the Naughties - the response was a non-plussed “There’s a programming language named after a snake?” and no authorization to bring it into the organization. That was frustrating.

As it progressed towards the mainstream, the people who used it were often C++ programmers who wanted to automate small tasks - those that didn’t need the performance gains C++ provided. These were much easier to quickly whip together in Python - and similar programming idioms could be used.

Further, due in part to the fast pace of development possible, a vast number of libraries was quickly written. The authors often found Python’s performance became a bottleneck (for example the dreaded GIL). Therefore easy ways to integrate with C++ were sought and built into the language. This lead to ctypes, SWIG, Boost.Python and PyBind11 (amongst others).

That pace of development provided a new value of Python for C++ programmers: the set of functionality in the Python libraries soon outstripped C++’s own. Therefore a mechanism for embedding a Python interpreter in C++ was developed. Python scripts could now be run within in it - e.g. to process complex regular expressions.

In our webinar Antony Peacock will discuss just some of the ways Python is used in trading houses and investment banks, with examples.

Rainer Grimm will present a few specific techniques of Python use with C++ and why you should use them.

Richard Hickling will show how to develop a C++ module that can be used in Python and show you its use live.