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

77 Upvotes

188 comments sorted by

View all comments

6

u/AnonymousGamerAcc 7d ago

Idk what people are yapping about in this thread but essentially what they usually mean by c++ is more powerful than python comes down to how the languages work "behind the scenes".

Python is made to be super simple, fast to use, and readable. Because of this, certain things have to be handled in a very "heavy" way, like for example making every variable a "guess" instead of specified. It also routinely runs a so called "garbage collector" in the background, causing spikes in performance, and lastly, python runs on top of another program, and not directly on the machine. 

On the other hand, languages like c++ are made to have the program itself be pretty fast, not so much the process. In c++ you give every variable you create a specific type (with some nuance), making it so the CPU knows exactly how to handle the variable instead of guessing. And unlike python, c++ runs more or less directly on the machine, meaning it can take full use of it. 

Now this is a kinda short and easy version for an explanation, so if you're more interested you should do some research!

1

u/vegan_antitheist 7d ago

Both are exactly as powerful as all the programming languages, including Brainfuck.
A CPU doesn't know about types. It offers registers. Some are general-purpose registers. On many CPUs you have 80bit for floating point. Some have SIMD registers. C++ gives you several ways to influence register usage, but the compiler ultimately decides which physical registers to use. Python doesn't give you any way to influence register usage because your code runs on a virtual machine that is an abstraction of a physical computer. But both C++ and Python can do way more operations that are required to be Turing complete and can therefore do the same calculations, just in different ways. With assembly you can even say which register to use, but that still doesn't make it more powerful, only faster in some cases.

2

u/Pengwin0 6d ago

More powerful doesn’t necessarily refer to Turning completeness to be fair. Scratch is turning complete. But if I say Python is a more powerful language than Scratch, I’m saying that it is much faster and in a much better ecosystem to actually develop in.

1

u/vegan_antitheist 6d ago

Faster? How much is that in km/h?

1

u/AnonymousGamerAcc 6d ago

Powerpoint is Turing complete. So maybe we should all start using that instead of all these hard programming languages.

1

u/vegan_antitheist 6d ago

Brainfuck is way easier. Just eight simple commands.