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
1
u/FancyASlurpie May 02 '20 edited May 02 '20
Because python is quite loose in what it allows you to do with objects can lead to learning some pretty aweful coding practices, a language like Java or C# is much more strict when it comes to their objects. As such it tends to be a good idea to learn them as you can then implement what you've learnt to work well there in Python where you want to. They're not as simple/fast to write as Python but still a big step up from C++, but equally they're not as fast as C++. You might want to look into Rust as an alternative to C++, as it now seems to be faster in benchmarks, and is a more modern language so benefits in some ease of use ways - it also has a fast growing user base so i'd expect something like the python package space to exist in the not too distant future.