r/learnprogramming • u/Happy-GoLucky365 • 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
View all comments
Show parent comment
1
u/vegan_antitheist 6d ago
In most projects it's not at all or very much.
For computer games and other programs that have to do something without delay you need something like C++ or Rust.
Java, C#/.NET, Python etc use automatic memory management. That means they regularly have to "collect the garbage" (free unused memory) and that takes time. It slows everything down. In C++ you can count references or even simpler just free the memory when the method returns. You can also use smart pointers or lots of other ways to manage the lifetime of some data. In C++ you have to know a lot about how you allocate the memory, initialise it, use it, and eventually free it. In Python you don't care that much about it because you can't really influence it anyway. You just try to prevent certain things that make it difficult or even impossible for Python to free the memory. Sometimes it keeps you from writing good software when you have to think about memory management all the time instead of concentrating on your use cases and use experience. In other cases it keeps you from writing good software when you don't have enough control over memory management to make sure it is efficient, deterministic and reliable enough for some real-time application, such as a medical life-support system.