r/Python • • 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.7k Upvotes

219 comments sorted by

View all comments

Show parent comments

4

u/[deleted] May 02 '20

I agree with these points. I read somewhere that Python > 3.7 solves the GIL problem?

10

u/mriswithe May 02 '20

There is some work going on with subinterpreters which are a little known feature that is different than multithreading and multiprocessing, I think it was on talk python where they were talking about a PEP that is trying to make it so that each subinterpreter had its own GIL instead of sharing one.

Found the link talking about it https://talkpython.fm/episodes/show/225/can-subinterpreters-free-us-from-pythons-gil

4

u/Zafara1 May 03 '20

As a side note, this is an area where infrastructure has come to fill the gap.

Containers and serverless functions can be used to offload this inefficiency from the code to the infrastructure running the code.

Don't need to code for multicore if I've got 1000s of independent cores running my code.

2

u/Yojihito May 02 '20

GIL still exists in the latest Python release.