<p>So, one commonly heard comment when talking about performance is that you write your code with whatever language gets the job done fastest. If performance in specific areas is a problem, then rewrite those bits in C/C++.</p>

<p>But, what if you're starting with a native C++ app? What options do you have if you want to write the easy bits, or refactor the old bits, in a language like Python, Ruby, C#, or whatever? Keep in mind that transferring data between the native and other sides is a must. Being able to simply call a function written in an "easier" language, while passing C++ classes as data, would be beautiful.</p>

<p>We've got a crusty Win32 app that would benefit greatly if we could crank out new code, or refactor old code, in C# or something. Very little of it requires the complexity of C++, and dealing with the little fiddly bits is dragging down the programming process. </p>

If you want to work between C++ and Python, than
Boost Python
is what you're looking for.  You can write C Python bindings by hand for Cython, but that limits in many ways how you're going to write your code.  This is the easiest way, as seen in some snippets from
this tutorial
:
A simple function that performs a hello world:
```
```
char const* greet()
{
   return "hello, world";
}
```
```
The Boost python code needed to expose it to python:
```
```
#include <boost/python.hpp>

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("greet", greet);
}
```
```
How to use this code from python:
```
```
>>> import hello_ext
>>> print hello.greet()
hello, world
```
```
Going in the opposite direction is  bit tougher, since python doesn't compile to native code.  You have to embed the python interpreter into your C++ application, but the work necessary to do that is documented
here
.  This is an example of calling the python interpreter and extracting the result (the python interpreter defines the object class for use in C++):
```
```
object result = eval("5 ** 2");
int five_squared = extract<int>(result);
```
```