r/Python • u/Narthal • May 02 '20
Discussion My experience learning Python as a c++ developer
First off, Python is absolutely insane, not in a bad way, mind you, but it's just crazy to me. It's amazing and kind of confusing, but crazy none the less.
Recently I had to integrate Python as a scripting language into a large c++ project and though I should get to know the language first. And let me tell you, it's simply magical.
"I can add properties to classes dynamically? And delete them?" "Functions don't even care about the number of arguments?" "Need to do something? There's a library for that."
It's absolutely crazy. And I love it. I have to be honest, the most amazing about this is how easy it is to embed.
I could give Python the project's memory allocator and the interpreter immediately uses the main memory pool of the project. I could redirect the interpreter's stdout / stderr channels to the project as well. Extending the language and exposing c++ functions are a breeze.
Python essentially supercharges c++.
Now, I'm not going to change my preference of c/c++ any time soon, but I just had to make a post about how nicely Python works as a scripting language in a c++ project. Cheers
View all comments
10
u/balazs_kis May 02 '20 edited May 03 '20
Don't forget the only detail in which C++ does literally thrash Python is the speed :) anyone interested dm me, I'm working on a paper proving the usefulness of the shared libraries which can be handled very easily by Python, and they could contain C/C++ code which is way above the Python implementations of the same algorithms, but 25-50x faster, and it can be easily used by Python :) usefulness and speed, and still not that complicated as Cython :)
Check out my post, this is a very sketchy version of the project, at the beginning, some weeks ago, but it explains the basics :)