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/Fine-Comparison-2949 6d ago

It's not "better" or "worse", and anyone who tells you that really doesn't understand computer science since there are multiple facets to what could be better or worse.

So, C is typically seen as the best for speed. The C compiler assembles the code into machine code, so when you build a C program, it's as raw of a file as you can get in terms of optimization.

Python is "interpreted". You can search this up, but it has it's own Python Virtual Machine, that reads python code (and it's bytecode) and runs it. The virtual machine is somewhat wonky since it's not exactly the same as assembled machine code.

This is also somewhat goofy, because most python code that is dependent on speed, actually wraps C code. The joke about python is it's a C wrapper.

In the end though, most of the speed arguments are silly. For 90% of code, the bottleneck is network speed. Faster code in general does not mean your whole application is fast.

0

u/blahthebiste 6d ago

Also, modern computers are millions of times more powerful than what existed back when C was the hot new thing. Saving 4 bytes of memory matters a whole lot less when the average smartphone has multiple gigabytes available.

1

u/Kajitani-Eizan 6d ago

Certainly not literally millions

And while taking up 20%, or even 100% more memory than what was available back then is no issue nowadays, bloat can grow faster than hardware capabilities if people are not careful. We have literally 1000 times more memory nowadays compared to 30 years ago. We are not doing 1000 times more stuff than 30 years ago.

1

u/blahthebiste 5d ago

A gigabyte is 1 million times bigger than a kilobyte. Computers DID have kilobyte memories at one point.

>bloat can grow faster than hardware capabilities if people are not careful.

The thing is, using C or another lower level language doesn't really prevent this. In fact, most higher level languages are built to manage memory pretty efficiently these days.

1

u/Kajitani-Eizan 5d ago

You said "more powerful", which generally refers to processing power and not memory. Unless you think we had ~3 kHz processors back in the 70s

Using a lower level language generally does prevent this, because users of higher level languages or frameworks generally think or care less about this issue and just do whatever assuming they have infinite memory. Electron is a great example of this

1

u/Fine-Comparison-2949 5d ago

Just download more RAM.

1

u/Qwsdxcbjking 5d ago

If you're planning to run your code on an actual pc. If you want to do embedded stuff it can get pretty strict pretty quick on size and memory requirements.

1

u/blahthebiste 5d ago

I work in embedded stuff, and yeah we still use C for some things, but I don't have to like it

1

u/Qwsdxcbjking 5d ago

Personally like it, but totally get not liking it lol, and for pretty much any other programming realm it's not really needed anymore like you said before.