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

79 Upvotes

196 comments sorted by

View all comments

Show parent comment

81

u/vegan_antitheist 13d ago

Both are Turing complete. There's nothing C can do that Python can't. The difference is performance. That's why you don't see many computer games written in Python. But someone ported DOOM to Python: https://github.com/hmofet/duum
You could port GTA6 to python and it would run. Just not at 30 fps.

4

u/no_more_cat_pics_pls 8d ago

Python can't be used for kernal or OS programming and it's lack of strong typing and no memory management make it much more prone to bugs and slower. You need very specific languages for certain things. C can't be used for websites like HTML but you can't just say they are turning complete and equal

3

u/vegan_antitheist 8d ago

Again: Both are Turing complete. There's nothing one can do the other can't. It doesn't matter how much some people want to deny this. I wouldn't even need examples to prove this, but those examples exist:

C can be and probably still is used for html. CGI programs built in C weren't even that uncommon in the 1990s. Amazon was just one example of a website made with C.

Amazon's first engineers coded in a computer language called C and decided to store the website in an off-the-shelf database called Berkeley DB

Source: The Everything Store: Jeff Bezos and the Age of Amazon (Brad Stone, 2012)

PythonOS is described as:

A bare-metal operating system where CPython 3.14 is the kernel — not a program running on an OS, but the OS itself.

Source: https://github.com/jordanhubbard/pythonos

1

u/cmdr_iannorton 3d ago

Python is a virtual machine, at runtime your python code is compiled to python bytecode, you are controlling this machine, the machine itself could by a c program (cpython) or even a .net program (ipython) but ultimately you are writing for the python interpreter not a cpu.

python includes its own compiler, simply implementing eval and reflection is something huge. a 1 line program that uses eval() needs the whole python interpreter and compiler. except for very specific hardware, python isnt going to be used for low level stuff

1

u/vegan_antitheist 3d ago

And yet, you can do all that in Python. Brainfuck, C, Java, or any other programming language. The statement "you literally can write any program in c/c++, you cant do that in python" is simply wrong. You can write any program in python.

1

u/no_more_cat_pics_pls 7d ago

Cool, sure a bike and a mustang can also both technically get you to the same place. Why not, both have wheels and theres nothing one can do that the other cant right?

1

u/parautenbach 5d ago

That’s a completely different argument from your previous one.

-36

u/mysteryihs 13d ago

There's nothing C can do that Python can't. You could port GTA6 to python and it would run. Just not at 30 fps.

So there is something Python can't do, it can't run games more efficiently than C.

52

u/Talbertross 13d ago

Obviously it means there are no computations that C/C++ can do that Python can't. Pedantic dingus.

16

u/EquipLordBritish 13d ago

Not only that, but it's also (pedantically) incorrect. You could write a python program that outputs a custom executable that is every bit as fast as C code. It would be very annoying to do and I doubt anyone would bother, but it could be done.

1

u/Moscato359 10d ago

That's not really the python hitting the target anymore though is it

It's python making an exe, not the exe being python

1

u/EquipLordBritish 9d ago

Seems like you could say something similar about compiled languages, since the compiler is what actually writes the program.

1

u/Moscato359 9d ago

I mean, sure, technically you can make a python compiler which compilers from python to ML, and then C to ML and say they're the same, but the python language isn't really built for that

Technically feasible, and practical are not the same

1

u/EquipLordBritish 9d ago

That's about what I said in my initial comment.

2

u/Moscato359 10d ago

It's not pedantic when your goal is to have an app within a performance target.

I want to write my game to run at 144fps

Well pure python can't do it

1

u/Talbertross 9d ago

Nah, you're just pulling some "can God make a boulder so big even he can't lift it" bullshit

1

u/Moscato359 9d ago

Uhm... Needing to hit a frame rate target is a very common thing for game development 

1

u/vegan_antitheist 9d ago

And still, it's just as powerful. What you can calculate and how long it takes are two very different questions.

1

u/Moscato359 9d ago

If you're for example, running a PC game, and one of your requirements is a specific frame rate, it's not as powerful

6

u/moratnz 13d ago

"The difference is performance"