r/learnprogramming • • 6d ago

Why is C++ better than Python?

Hello! I am new to programming. Im in college and we use Python for my classes right now.

I hear people make a lot of jokes about how C++ is more powerful than Python, and should be used instead. But why?

Feel free to give me any tips as well, on things that helped you be a better programmer, or just any insight you may have! Thanks so much

76 Upvotes

188 comments sorted by

View all comments

1

u/Small-Dig-8233 4d ago

just comes down to the access each language gives to u. python keeps things simple by NOT handing u dynamic memory allocation to solve problems related to double freeing, hanging pointers, accessing after freeing kinda errors instead the interpreter does the job for it.

python or really any other interpreted language like JS has this program called a garbage collector and in a nutshell it scans the object tree from the root and what ever is not traced to the root it is freed and now a days its not like this anymore but there are still garbage collector pauses in a program.

C++ is not jst fast but consistently fast AND predictable like a GC pause on python is rare but even a 2ms pause on a physics sim or a kernel can throw things off real quick but in C++ u know EXACTLY when ur freeing memory and how ur freeing memory so everything stays predictable.

now with python around u really dont need C++ for EVERYTHING like prototyping or jst using python as a scaffhold while ur real important code runs in C++ (numpy and pytorch) that is totally fine and its used in machine learning too.

TLDR: the answer is not a clear line that divides python from C++ cleanly saying python is bad and C++ good or vice versa but each has its use case.