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

67 Upvotes

185 comments sorted by

View all comments

Show parent comment

-1

u/vegan_antitheist 5d ago

it gives you real control over the hardware to a very minute level. 

Does it? Compare to Python it certainly does. But it's high level compared to assembly.

 time difference of a basic for loop

I don't think that's a good idea. Beginners just end up on some shitty website written by beginners who don't know shit, or someone just writing to get traffic to sell more ads who also doesn't know shit. And it would be misleading if it claims that it's different. Some Python implementations have JIT and then a simple loop should be just as fast. Too simplistic loops might even end up replaced by a constant by a good C++ compiler. Then the time complexity is literally O(0). You probably don't get that in Python even with JIT. It doesn't even optimise tail recursion as far as I know and the reason is that debugging would be confusing when your recursion doesn't actually do any recursion.

4

u/YouPeopleCantBeReal4 5d ago

Assembly is pretty high level compared to logic gates

0

u/xarop_pa_toss 5d ago

There's always the "assembly is the real low level language" guy isn't there? The post was about the differences between C++ and Python so that's the basis for my comment. Maybe we should all just program with NAND gates...

And a beginner isn't going to understand all the stuff your said and probably not even find it. But there are nice comparisons out there that show clear differences, which leads to other explanations on compiled vs interpreted languages for example. It's not that deep man

2

u/moratnz 5d ago

Given the amount of speculative execution, memory caching etc., that goes on in modern CPUs, no languages are 'low level' in the sense that people generally mean. Even good old C is numerous abstraction layers away from what the actual hardware is doing.

1

u/CowBoyDanIndie 5d ago

Ya, no modern high power cpu runs its instructions set natively, they are all emulated by microcode.

0

u/vegan_antitheist 5d ago

C++ is a high-level programming language. That's just a fact. A high-level language provides abstractions that allow you to express computations without directly dealing with the processor's instructions and hardware details. C++ does that. Loops, variables, types, even simple operators, like a+b, are high-level. The compiler handles instruction selection, register allocation and many other hardware-specific details.

This is a fact and your down vote doesn't change that.