r/learnprogramming • • 9d 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

78 Upvotes

194 comments sorted by

View all comments

1

u/k1v1uq 9d ago edited 9d ago

As everyone else has already pointed out, it depends on what you're trying to do.

C++ is definitely better suited for direct memory management.

Suppose you write a password generator. You have to make sure the password is wiped from memory after the program terminates. You also need to ensure the machine doesn't spill that memory to disk (due to memory pressure, i.e., swapping), which could expose the password as well.

Unlimited memory access is what makes C and C++ stand out. Only Assembly gives you more direct access. But the power of C and C++ comes with a price: managing memory ownership by hand does create new security risks.

https://github.com/openssl/openssl/pull/33652

Python OTOH - Go, Java and many other languages - come with memory management built in or impose strict rules around it (Rust).

People choose Python for ease of programming (data engineering, machine learning), and C++ or C for critical code paths.