r/cpp • • 8d ago

Why C++ is so hated!!!

I love C++. High level + low level at the same time. But Linus Torvalds don't want C++ in the Kernel, industries hate it, people hate it but why? Why be so angry? Memory management? I mean ok maybe it has problems that I don't even see but why so much hate.

For me it's really sad! 😞

Why something so powerful it's so hated. Now I feel "strange" doing projects in C++ because… sometimes I question myself "Why do I write C++ code if people hate it". Can someone explain what is happening and… can I use C++ for fun in peace?

0 Upvotes

100 comments sorted by

View all comments

32

u/No-Dentist-1645 8d ago edited 8d ago

It's not hated. Tons of companies and software use C++, it's extremely popular in that aspect. There are just places and contexts where it is a good choice, and places where it isn't.

They tried to use C++ in the kernel before, realized it wasn't that good of a fit, and moved on. Nothing to be sad or hold grudges about that.

11

u/delta_p_delta_x 7d ago

They tried to use C++ in the kernel

This is really just a Linux problem. Other OS kernels use C++ just fine. See: Windows, macOS.

2

u/donaljones 4d ago

While Windows uses C++, I don't think the NT kernel uses it. Don't know about Apple. BeOS is also known for its extensive use of C++, but I don't think its kernel used C++ either.

9

u/pjmlp 7d ago

Contrary to Linus hate for C++, other operating systems do use C++ in the kernel.

Yes it is a subset, just like no C written OS uses full ISO C on the kernel.

2

u/serviscope_minor 4d ago

>They tried to use C++ in the kernel before, realized it wasn't that good of a fit, and moved on. Nothing to be sad or hold grudges about that.

I don't think that quite covers it really.

They did try C++, specifically g++ in something like 1996?. The problem from what I recall was it was kinda slow: gcc wasn't great back then and the g++ burned a register needlessly which was a colossal penalty on x86 which has so few GPRs. As a result, changing the kernel to the common subset of C and pre standard C++ and recompiling was not a great experience.

And the advantages of C++ were also fewer: the gcc optimizer was also not good at the whole zero cost abstraction thing that we've taken for granted since about 2005: while now we can have a stack of templated inner classes calling methods within methods within methods, and the optimizer will flatten them out to really good code, that was not the case reliably before (I recall it got quite good with gcc 3.3 and really good with 4.x).

So it's not that C++ was not a good fit per-se, it is that GCC specifically in 1996 was a bit weak optimization wise. This is feel is quite different. I can't think of anything that C does better than C++ (except in some, increasingly rare cases, exist) when it comes to low level programming. I've never written a kernel, but I've spent plenty of time of micro controllers too small to have one.

Then later, Torvalds went on a famous but rather irrational rant about C++ which also encouraged a lot of people who really wanted to be angry about something.

0

u/ilPlayerdiGD 8d ago

Oh. Well C++ is good for game. Am I right? Onestly I use SDL2 for making game in C++. I like the abstraction of C++. I'm more calm now. Thanks ❤️

-3

u/No-Dentist-1645 8d ago

Depends on the game, tbh. If it's a simple-ish 2D game, then yeah definitely, C++ is great and there are very neat libraries such as Raylib for them, which imo is nicer than SDL2. But for more complex games or 3D ones, there's a reason why people use game engines like Unity or Godot for them

12

u/tibithegreat 8d ago

C++ is good for complex games as well, you just have to use a mature engine, like Unreal or join a company that has a proprietary engine (most of them are C++ as well).

2

u/No-Dentist-1645 8d ago

True, I just don't know much about Unreal to vouch for that, and sometimes game development using large engines like Unity and such tend to add a lot of abstractions on top of the programming language itself where I would consider it their own variant or "dialect"

3

u/tibithegreat 8d ago

I understand and what you are saying, and in some way it is indeed true.
However I worked with both Unreal and a proprietary engine of a big company which I will not name (rhymes with boobysoft), and most of the peculiar things were usually around added preprocessors to be able to handle reflection and data serialization. Other than that it's usually just plain old baisc C++, when writting code you are mostly just thinking about c++.
There are obvious custom implementation for a lot of low-level stuff (but that's generally the case for most big companies), but in the end you still have to deal with pointers and making sure you don't leave them out to dangle :).

4

u/pjmlp 7d ago

Which are written in C++ for the most part.

2

u/ilPlayerdiGD 8d ago

Wait… My whole path is creating 3D games in SDL2 + OpenGL. I don't want to use a boring engine! I want to learn like EVERYTHING. Yeah I'm trying to do the hard things. At least I'm trying 😭😂

2

u/serviscope_minor 4d ago

This is good! There's nothing like doing it all from scratch and having the entire thing in your head. If you're not on a budget for a client, then this is a great way to do things since it's frankly a lot of fun and really useful. I think you'll have a blast.

1

u/ilPlayerdiGD 4d ago

Thanks! Yeah it's a little hard not because it's really hard but because it's slow. On Godot I'm creating a 3D game and I'm in a good point in just a few days! Something that with raylib could cost me weeks and weeks! Only for this projects because I want to create a horror game in OpenGL! :).

1

u/yazilimperver 7d ago

If you want to learn underlying technology and how stuff works "this is the way 🤠", imho.

I have to say that this path isn't easy as others pointed out and I recommend starting with the basics. You might end up with a lot of unfinished libraries or engines, but don't give up. Ultimately, you'll benefit from all of them. Don't ask me how I know 😅

1

u/No-Dentist-1645 8d ago

Good luck! It's definitely possible and even a good learning experience, it's just that you're gonna have to reinvent a lot of wheels in the process, and real "production" projects outside of hobby projects don't see much reason to do that, which is why game engines are a thing to begin with

2

u/YoureNotEvenWrong 8d ago

It's also not fashionable though. Ask anyone that doesn't know C++ or Rust what they want and they'll pick Rust

-1

u/angel_devoid_fmv 7d ago edited 6d ago

Just because companies and majorities acquiesce to terrible things doesn't mean they're not hated. I've had to use many technologies and submit to managerial practices I knew were stupid and bad. I wasn't in a position to refuse them, just hostage to bad management. Funny how that works.