r/cpp • game engine dev • Mar 29 '26

Can I rant for a minute.

Call me weird but I think the majority of C++'s issues stem from one very fundamental problem: the language cannot evolve because everyone is against both breaking ABI and changing core language features. Yes, this is another one of these posts. Allow me to try something new.

I think everyone already knows how we got here and this is what's driving me nuts. I don't understand why there hasn't been a push to actually solve it. Like, actually push against the entities that are against breaking ABI or updating the core language and allow the language to actually move forward instead of tiny baby steps. As Bjarne has said, there's a better, less-complicated language inside C++. We'll never see it with our current self-imposed limitation. It is clearly a self-imposed limitation and quite frankly I find it ridiculous we're still here. It's not like C++ is the only language and other languages haven't found a way around this issue with one solution or another. (The PHP7/8 debacle comes to mind.)

Against all reason, I love C++. Don't ask me why. I've been using this frankenstein language since I think the early 90s. I continue using it now and have written a (very playable) 2D game engine with it. And, as with any experienced C++ programmer, my issues with the language are numerous. To name a few:

  1. I think vector, string, and a few other STL types should have been baked into the language.
  2. We have way too many ways to initialize a variable.
  3. Argument passing is unnecessarily complicated compared to other languages.
  4. The h/cpp compilation model is a dinosaur.
  5. Why did we get copyable_function instead of function2? Or just update function to begin with? Let's not even get into that discussion.
  6. Modules seem almost terminal upon arrival. (Yes, I've heard both that they are basically usable now, and also that the spec is fundamentally flawed.)
  7. People are already complaining about reflection including STL headers because it needs vector. Don't even get me started on the prospect of something like refl_string and refl_vector.
  8. Destructive moves.
  9. Let me know in the comments if I didn't include your favorite issue.

C++ has had some very nice evolutions. C++11 was great. Reflection will hopefully be a great addition. (Modules was supposed to be a great addition but let's not go there right now.) But there are so many competitor languages at this point it's just bonkers there are few or any attempts to solve the fundamental issue: C++ cannot grow because it cannot get out of its own way. Would C++ have so many flawed (map/set) or downright unusable features (regex) if there was a feasible way to go back and fix them? As an aside, I tried using std::regex in a utility for my game engine. At this point it would likely take over 2 minutes to execute said utility. Using CTRE, it executes in just a few seconds.

I honestly think it's no secret why Circle, Rust, and Go exist. Would they exist if C++ had an effective -- or at least, agreed-upon -- way to break ABI? (Or, ISO forbid, breaking ABI wasn't necessary by some means.) I have doubts about the feasibility of something like std::network because if one security hole is found that affects ABI, the whole thing becomes basically permanently unusable. Something like std::gui would also be dead upon arrival.

C++ specs get one chance to get it right. If they don't -- and unfortunately the rate is not 100%, which is unattainable anyway -- it's extra complexity in the language that is, for all intents and purposes, a "noob trap". I think this is dumb. I can't be the only one. I have to imagine this "we must get it right on the first shot" is also what makes passing a new paper outrageously difficult.

I really don't want to hear "we can't because breaking ABI would break tons of applications". I still think it's a self-imposed limitation, and it is time to recognize the heavy damage it's done to the language. You're limiting the evolution of the language to the extreme detriment of its usability. I personally cannot overstate this. The solutions are many, and if it comes down to "every major C++ release is an ABI break" so be it. C++'s technical debt is piling up and its complexity grows to a ridiculous degree with every half-solution. I wouldn't be surprised to see C++'s usage fall off a cliff because the basic problem is its barrier to entry is too high.

I haven't used C++ nearly as long as some but I'm already really tired of this awkward compatibility dog and pony show. We know why the competitor languages exist: primarily to fix issues in C++ that could very well just be addressed in C++ instead. There's a lot of smart people inside (and outside) the C++ community. For our own sanity, I really think it's well past time to put together a team of people to address this instead of giving us reflect_only_function. At least some of these problems are quite down to the fact that many things that, in my opinion, should have been language features were instead of implemented as library features. vector<bool> could long have been addressed if it wasn't in a header.

I'd love to help solve this problem, but I'm only one person and I'm by no means a C++ expert (given the famously high skill ceiling of C++) but it affects my day to day. I really wish C++ could actually start picking things off its wish list instead of continually punching itself in the face (see 8-point list above). I'm not going to list what I think C++ should do with breaking changes because not only can we not agree on breaking compatibility, we can't agree on how to consistently name things. I don't know what the solution there is but I do constantly wonder if awkward naming could also be fundamentally solved by allowing breaks. Maybe then we wouldn't have "copyable_function" because it would just be "function".

[Edit]

Some additional comments from the comments.

  • I'd like to see the conversation move from "should we" to "how do we" and find out if any solution can make everyone at least sort of happy. The obvious common answer is breaking compatibility at every major version but clearly that makes the larger entities very unhappy. (Part of me wonders if they should have such control -- to the detriment of others, in some cases, if it is "for the best" -- but that's whole other discussion.) The other obvious common answer is epochs. But simply arguing "should we" I think is a waste of time. I personally think it's a damn shame the epochs paper was (if I remember right) turned down rather quickly. It was, at least, a starting point. At the very least, defining what you'd want out of a C++ versioning system would be nice. Perhaps modules was a poor starting point, given how long it's taken for them to become usable.
  • There are a number of things in the language that are fundamentally flawed to the point they are basically unusable. (For me, if this number is higher than 1 it is to high.) This fact tends to get swept under the rug because we can never go back and fix them if the change involves syntax or ABI. Regex is really quite bad. It is not the only thing. It contributes to the difficulty in teaching the language.
  • Yes, C++ really has some awful defaults and traps. Debating whether auto should recognize "T&" returns, automatically preventing a copy, is always a fun discussion. Boy, would that cause a disaster if it were to be changed.
  • To the original readers: yes, I'd like to see both ABI and core language breaks. I've modified the post to make that clear. Perhaps we could start with one of them. ABI breaks are clearly harder because it affects dynamic linking.
  • I've never been to a C++ committee meeting but I just want to point out again: would we have such awkward naming for some things if breaking changes to the language or ABI were allowed? Is the sole reason copyable_function exists because we couldn't change function? Point is: ignore the discussion on the name and instead specifically if the change should have simply been to function in the first place.
145 Upvotes

266 comments sorted by

View all comments

Show parent comment

1

u/domiran game engine dev Mar 29 '26 edited Mar 30 '26

And this is the thing. C++ solves my needs. It works well enough. But it's becoming a disturbing monster and at this rate the complexity is getting worse and never going to come under control. I think it's silly a technical field like this where growth, sustainability, and maintainability is such a large part of the work itself doesn't see the growing issue with the very tool they're using and are simply actively making it worse.

C++ doesn't need to fundamentally change, I don't think. (I guess this also leans heavily on your definition of "fundamentally".) But its tech debt, I think, is highly related to its complexity. We can't address its complexity because we can't address its tech debt. I'm not demanding C++ add, say, C#'s ref or out keywords. I'm not demanding C++ condense/unify its variable initialization but it would be extremely nice.

Do we really need both T& operator=(T&&) and T(T&&)? I have to duplicate this code because that's just how the language works. It feels silly, doesn't it? This kind of language change would break code just as drastically as an ABI break (perhaps more) but it's this weird kind of tech debt that's been sitting in the language for so long. C++11 added moves and added not one set but two sets of constructor/assignment.

At a basic level I really just want C++ to stop being awkward. std::function vs std::copyable_function. Fixing fundamental performance problems in various STL classes because we know better now. If this also includes more fundamental changes, like simplifying argument passing, addressing vector<bool>, baking string or vector into the language, simplifying initialization, const by default, then I'd really get my full wish list.

Of course, this is the crossroads the language faces and is the heart of every argument on ABI. Is ABI stability a strength or weakness of C++? I think it's becoming a liability and those who need/want the stability vs those who want to see it broken to fix technical debt need to come to a compromise. I just haven't seen anything I'd call strong enough to get the larger conversation started. It's been smatterings here and there, just like this post.

15

u/biowpn Mar 29 '26

Why do you want to bake string and vector into the language?

2

u/domiran game engine dev Mar 29 '26

One of the contentious issues with reflection is the need to include the STL vector header. If you don't use the STL, now you are forced to. If you are using C++ under a constrained environment, you may not be able to include the STL. But now you have to, and thus can't use reflection. If vector was baked into the language, this issue vanishes.

5

u/no-sig-available Mar 30 '26

The standard already allows a compiler to have a built-in vector or string. The standard carefully says "the vector header", not "header file", so it doesn't have to be a file.

Or the file could contain the equivalent of using vector = __builtin_vector;

It is just that no compiler provider has seen the advantages of doing that.

→ More replies (8)

16

u/DeepReputation Mar 29 '26

To be fair, unless the move constructor and move assignment have trivial implementations (which means they can just be default declared), they do need to be implemented differently in most cases.

Also, what you're calling for is not an ABI change, but a language spec change in a non-backward-compatible manner and nobody will ever do that, because that's a selling point of C++. Big tech have lobby in the C++ standard, and they have monorepos with 10s of millions of LOC in C++. They absolutely don't want their monorepos to undergo major changes in order to upgrade to new C++.

1

u/domiran game engine dev Mar 29 '26 edited Mar 29 '26

Yeah, I understand that comment was mostly just language changes.

I also wonder how many of those large corporations are even upgrading their compiler or IDE for older projects. The last company I worked for tended to err on the conservative side and you'd be hard-pressed to be able to even upgrade the IDE, let alone the compiler, for a particular project unless it was explicitly approved by the PM. (And for a long time it was not allowed at all.)

There are plenty of times where upgrading your compiler can cause days of rework just fixing things, so it's not like even now upgrading is free.

2

u/DeepReputation Mar 30 '26

Some large companies have monorepos (like Meta or Google). They do upgrade compiler version, and they have dedicated teams to do so. The upgrade doesn't happen often, because it's a very involved process, given the wide-reaching effect of the change.

7

u/slithering3897 Mar 29 '26

Do we really need both T& operator=(T&&) and T(T&&)?

Do https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Copy-and-swap.

1

u/domiran game engine dev Mar 29 '26

I hate that some of these things have to exist. 😭

3

u/slithering3897 Mar 29 '26

But it's a beautiful idiom!

1

u/Wooden-Engineer-8098 Mar 30 '26

Actually, you shouldn't do that. Always taking a value is more work than taking lvalue or rvalue ref as needed

1

u/slithering3897 Mar 30 '26

Have you got an example?

2

u/Wooden-Engineer-8098 Mar 30 '26

Value will always be constructed, resulting in extra constructor call. Either copy constructed or move constructed, depending on argument. Even fast move constructor is worse than no constructor

1

u/slithering3897 Mar 30 '26

That's the theory, but optimisers are pretty good.

1

u/Wooden-Engineer-8098 Mar 30 '26

Optimizers are already stressed enough, why give them extra work?

0

u/[deleted] Mar 30 '26

[deleted] — view deleted comment

2

u/domiran game engine dev Mar 30 '26

You know what, I'm dumb, let me take that out. I don't think I've actually done that in years.

5

u/Wooden-Engineer-8098 Mar 30 '26

C++ solves not just your needs, but also needs of millions of others. What makes you think your needs are more important and c++ should stop solving needs of others?

And how can you write programs and not understand fundamental difference between assignment and construction? Assignment has to destroy existing value, while constructor doesn't

0

u/domiran game engine dev Mar 30 '26

Touche, by keeping C++ as-is you're also ignoring the needs of other millions. There are very legitimate arguments to preserve stability but I do not think this is one of them.

And I was referring to the practice of, say, writing your copy constructor as "*this = other", relying on the copy constructor, but as someone else pointed out I realized I was being dumb. I haven't actually done that in quite some time, with one of the obvious reasons is you're ignoring the benefit of member initializers.

1

u/Wooden-Engineer-8098 Mar 30 '26

What other millions? Are they in the room with us?

0

u/domiran game engine dev Mar 31 '26

I mean, by the same token, where are the millions you're talking about?

I'm really tired of your adversarial conversation style and will no longer be replying to you.

2

u/Wooden-Engineer-8098 Mar 31 '26

I'm talking about current c++ users. You are talking about your imagination

2

u/serviscope_minor Mar 30 '26

Do we really need both T& operator=(T&&) and T(T&&)?

Yeah I think we do, personally. If you don't you can implement one in terms of the other quite easily. I wouldn't call that tech debt so much as a design choice.

Mostly though I never implement those. I use encapsulated types and let the compiler implement them for me. If you're duplicating a ton of code because of this, I would say you're holding it wrong.

At a basic level I really just want C++ to stop being awkward.

Yeah same.

Fixing fundamental performance problems in various STL classes because we know better now.

Well... I mean yes. Mostly no. Trouble is, it's not ABI but API compatibility. The favourite bugbear of non-benchmarking randos is that unordered_map is slow. But if you look at it compared to maps that do guarantee iterator stability, it's pretty decent. That's an API problem: if you break the API, then even if people can recompile the world (also FFS people you need to be able to do that!), it might silently break code that relies on properties that no longer hold.

Everyone's second favourite bugbear: I maintain that the std::regex API is hostile to efficient implementations, because it's far too compile-time configurable. The only real ABI breaking fix it to bake in some uses of std::regex as fast paths and have the majority of the space of regexes being slow. That's a bit footgunny really, but maybe the best choice. I mean if normal use of regex was fast I wouldn't be sad!

baking string or vector into the language

Well akshually... it kind of is. According to the standard, anything defined in the standard is special so std::vector is part of the language. Which was irrelevant until C++26 where it's really really part of the language because reflection.

But, I'd say if there's problems due to std::vector not being part of the language (as it were), the solution is to fix the language, not bake in vector. The reason for that is one of the goals of C++, and something I like about it, is that user defined types should be as powerful and flexible as builtin ones. I think that's why C++ has some truly great libraries.