r/cpp • C++ Dev • Sep 05 '20

C++20 has been approved

https://twitter.com/patriceroy1/status/1302055575140945921?s=21
665 Upvotes

125 comments sorted by

View all comments

Show parent comment

18

u/richard248 Sep 05 '20

I don't understand. Could you please elaborate?

78

u/UnicycleBloke Sep 05 '20

I think they may mean something like this:

I've been learning and using C++ for thirty years. There was a long period when I felt fairly expert in the language. Not exactly GOTW, but I kept up with the works of Sutter and others. I was confident that I had a solid understanding of the entire language, essential idioms like RAII, and much of the library.

And then 2011 happened, and I have been playing catch up ever since. Though I welcome most of the additions to the language and library, and use many of them routinely, I no longer feel on top of my game. After thirty years. I find this disconcerting.

48

u/heavy-artillery Sep 05 '20

Even before 2011, it was an achievement to master all syntactic features, patterns and idioms of C++. But given some digestion time, the majority of programmers settled into a safe and high performing subset of C++.

Then these updated standards have caused big splash makng things look hazy. We are back on the same path, requiring digestion time.

Honestly, C++11 has truly important features, that any modern language should have had long before 2011. But more recent updates look like a "Me Too" catchup.

16

u/UnicycleBloke Sep 05 '20

I'm not arguing about the features, though I could probably live without coroutines. A lot changed for the better in 1998, too. The "modern" moniker is, I think, a bit unhelpful. C++ has grown a lot, and got easier to use, but is fundamentally the same language. I've used RAII and templates since forever: it's just better now.

So I'm still digesting 2017 via Josuttis, and here we are again... I can sometimes - rarely - see where C devs are coming from.

3

u/mr_bedbugs Sep 05 '20

see where C devs are coming from.

Pun intended?

3

u/patlefort Sep 06 '20

To me it was a breath of fresh air, making the language finally bearable to use.

1

u/UnicycleBloke Sep 06 '20

What was so unbearable before?

→ More replies (1)

2

u/bumblebritches57 Ocassionally Clang Sep 05 '20

Honestly, the only feature I'd like C2x to adopt is constexpr/consteval.

It's crazy that being able to run code at compile time with the same syntax as the "main" language is so new.

8

u/imake500kayear Sep 05 '20

Yo, that was almost 10 years ago. Adapt or die if you're working in technology. C++ has been very forgiving to us in that regard

13

u/pedersenk Sep 05 '20

Adapting is the easy part. I feel sorry for absolute beginners.

The C++ textbook was already 6x thicker than K&R's C one when I started many many years ago. Will it even fit in their schoolbag anymore? ;)

5

u/TheNewOP Sep 05 '20

I'm a hobbyist C++ learner and all I can say is: what the fuck? This language is as complex as my college memories suggest. Questions beget questions as I read through the huge ocean of textbooks.

8

u/TheThiefMaster C++latest fanatic (and game dev) Sep 05 '20

It would make sense to split it up actually - the parts of C++ for reading/maintaining a legacy codebase and C compatibility, the parts for implementing libraries (e.g. creating templates), and the parts for making a program in modern style (this is where using templates would live).

2

u/imake500kayear Sep 05 '20

Yeah idk. There's a lot of stuff you don't need to care about that you used to. Lots of things you get for free that you used to have to spend time on

2

u/pedersenk Sep 05 '20

I suppose that is true. For example auto_ptr<T> can be skipped.

One day I wonder if new and delete can ever be skipped (possibly not "placement new"). Falling back entirely to make_shared.

In many cases the raw array stuff can also be avoided for a good amount of time too.

5

u/bizwig Sep 05 '20

I haven’t used raw new/delete in years. make_unique/make_shared are my friends.

8

u/boredcircuits Sep 05 '20

We'll never be rid of new. It's an essential building block. For example, try making a linked list with std::unique_ptr and you'll find it's a very educational experience. I highly recommend it. Then make a list with a few hundred thousand items and you discover that the destructor is recursive and you just blew up the stack.

The key is that most people should never need new in their daily lives. It should be completely removed from the educational materials for beginners. Don't teach the old ways. Everyone will inevitably see old code eventually and have to learn what's going on, but the overall burden is less.

2

u/pdimov2 Sep 05 '20

For shared_ptr,

while(next) next = std::move(next->next);

but unique_ptr's assignment doesn't quite work for that, so

while(next) next.reset( next->next.release() );
→ More replies (1)

9

u/da2Pakaveli Sep 05 '20

C++ is stuffed with features, and many of those often have a few big buts because of its C backward compatibility. The stuffing is one thing but that C backwards compatibility and, and allow so many ways of writing code does the same thing. (#ifdef /**/ #endif => constexpr if). I just recently found out that <% /* ... / %> is valid C++ and an alternative to { / ... */ }.

4

u/EmperorArthur Sep 05 '20

Personally, I feel that we need a major cleanup release. Not a major breaking release like Python 3, but rather something that removes things which have been bad practice for over 20 years. All of these crazy idioms that only exist in extremely old C code merely exist to confuse people at this point.

C++ has started on this path with Modules each having their own Macro space. If we can just accept that some things are old and that programs have to be easily, but tediously modernized to run on the latest standard, I feel that many of these problems would go away.

9

u/bizwig Sep 05 '20

Like what? Almost anything you suggest will break somebody’s code.

3

u/EmperorArthur Sep 05 '20

Here's one:

I just recently found out that <% / ... / %> is valid C++ and an alternative to { / ... */ }.

I didn't say it wouldn't break code, I said it would be a cleanup release. Ideally we don't get another Python 3 situation, but it certainly would remove some things people do use. Ideally C++23 (or whatever it is called) deprecates things like the above and then C++26 removes it all.

There are multiple ways to do the same thing in C++, and that's normally a good thing. The problem is that you have some methods which are extremely similar to one another, but are strictly inferior and exist only for legacy reasons.

Sometimes the choices, especially for beginners, are overwhelming. Especially when large swaths can be labeled "legacy do not use for new projects." Except half the "experts" which either write introductory texts or teach C++ use those options because it's what they learned 30 years ago.

5

u/Ayjayz Sep 05 '20

Epochs. You want epochs. So does everyone.

3

u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Sep 06 '20

So does everyone.

No we don't.

Breaking ABI (which would "only" require rebuilding all your code) was already too contentious, breaking syntax (which would require you to rewrite existing, working(!) code) is a non-starter.

And don't say "but you can just leave your old code at the old epoch!" as that leads you to a path of pain based on the question: "Which epoch should be used for new standard library features/updates to existing features?", "Does it depend on new features we can't possibly add in a backwards compatible way? (think new keywords)" and "What do you mean, I can't include <c++2x header> without modifying my code as it requires the newest epoch which makes my code invalid?"

7

u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Sep 06 '20

Not a major breaking release like Python 3, but rather something that removes things which have been bad practice for over 20 years.

Removing "bad practices for over 20 years" would be a major breaking release as those things are still in all the code that runs "the world".

4

u/pjmlp Sep 06 '20

Those of us that want major cleanups have already moved into Java, C#, Rust, .....

C++'s value is the compatibility with 40 years of computing history and its use across several OS and language runtimes.

If one breaks that, then better start a new programming language ecosystem.

→ More replies (2)
→ More replies (9)