Remix.run Logo
coffeeaddict1 4 days ago

This is actually useful, but despite it is another extra thing you will have to remember when reading C++ code. I guess with LLMs things aren't so bad.

einpoklum 4 days ago | parent | next [-]

You need to remember _less_, rather than more, when you use this kind of vocabulary types. Think about std::optional. Before that (and if you didn't write something like it yourself), you had to, for each class, remember the bespoke semantics of when and how it represents the lack of some members, and you would have to have non-defaulted ctors, move assignments and dtors, and then whenever you used that class you would need to think about what those custom method do, which might be different than other classes which have optional members. Now you just tell yourself "oh, it just has an optional member, no biggie". Look at my comment above regarding how short the implementation of Widget becomes when you squeeze the juice from having the rule of 0.

coffeeaddict1 4 days ago | parent [-]

No. This is not what I meant. I absolutely agree that std::indirect is an improvement. My point is that when dealing with C++ code, now there is yet another way of doing the same thing. I will have to remember both ways, because people will still keep using the old way.

einpoklum 4 days ago | parent [-]

Ok, well, you have a point, in that you might see the old way of doing things and you might see the new way. This is, however, one of the detriments of the language's commitment to backwards-compatibility: Old-C++ code is (almost without fail) valid new-C++ code.

When you write new code, this is (mostly) not an issue; when you have to maintain old code, it is. Especially if the existing codebase is somewhat of a patchwork of code introduced at different points in time - pre-C++98, C++98, C++03, C++11 and so on. For this reason it is a saintly virtue to manage to unify the C++ "vernacular" used in a project, for better readability by newcomers and for facilitating uniform changes to the entire codebase later on.

skrebbel 4 days ago | parent | prev | next [-]

Why? It’s still the good (bad) old pimpl pattern. It just got a bit shorter. When reading you dont even need to grok “std::indirect”, you see the word pimpl and you know what’s going on.

coffeeaddict1 4 days ago | parent [-]

Because I will still encounter people who use the old of writing pimpl. So I now I'm forced to remember the old way + new way. People aren't magically switching to use std::indirect. I bet that even in 10 years, half of projects will still be using the old way.

MaPi_ 4 days ago | parent | prev [-]

I don't really get why people keep repeating the "C++ is too big" complaint together with the implication that you need to remember the entirety of the standard library. In comparison Java has networking, GUI framework and even MIDI in its standard libraries. Is it because C++ is more closely related to C which library is so small that it barely contains anything useful? I much prefer code that uses a library feature rather than yet another poorly implemented and not documented hand rolled version of it.

dooglius 4 days ago | parent [-]

Networking, GUI frameworks, and MIDI are presumably all self-contained and you would not need to be familiar with them except when working on networking, GUIs, or MIDI files, respectively. This is a general-purpose thing that could show up in any c++ code.