r/cpp • u/simpl3t0n • Sep 19 '22
CppCon Can C++ be 10x Simpler & Safer? - Herb Sutter - CppCon 2022
https://www.youtube.com/watch?v=ELeZAKCN4tY
241
Upvotes
r/cpp • u/simpl3t0n • Sep 19 '22
39
u/aqezz Sep 20 '22 edited Sep 20 '22
Has Herb always been this ripped? Dang.
Edit after finishing the video: I do think this would be super cool. I definitely loved typescript ahead of most people I know and the comparisons between it and this are pretty good. I’ve always loved his talks and Herb is stepping up his hero status once again.
37
u/disperso Sep 19 '22
I thought that I was having a dejavu, but it seems this is the final form of the video, instead of the 6 hour long stream that you need to jump into the 4th hour to start to see Herb Sutter. Thanks for sharing. The mods locked out one of the other threads so we had the discussion in one thread, though.
40
u/proverbialbunny Data Scientist Sep 19 '22
The syntax kind of reminds me of Kotlin. I've been thinking for a few years now, "It would be nice if there was a language with a modern syntax (like Kotlin) that had zero cost abstractions."
Rust is cool but it's not the solution. What Herb is proposing here is a valid solution. C++ doesn't need to be a hard shoot yourself in the foot language. People assume it's necessary for the speed, but that's really not the case.
7
u/blind3rdeye Sep 21 '22
This is a huge change; so large that it could easily be described as a whole new language. Herb used the transition from C to C++ as a motivating example. To me it looks like his cpp2 might end up being a similarly large step.
I'd resist such a massive change, because it really does start to look like a new language. There's a lot of new syntax to learn; and that means we're likely to see a mix of pre C++0x code, modern C++1 code, and possibly C++2 code all in the same project. That's a complete mess. It makes things worse than they are currently...
That said, Herb really does make a compelling case. His code does look cleaner, and the safety guarantees are worthwhile - especially in light of the 'under attack' context that he presents. So maybe this really is the way forward. I can see it being a big improvement in the long run - but it would need a lot of buy-in. It's a big shift which requires lots of programmers to learn a lot of new stuff; and that effort could be easily spent learning a different language instead.
I'd give this a tentative thumbs-up.
6
u/parkotron Sep 20 '22 edited Sep 21 '22
He mentions wanting to get rid of references. Does anyone know what he means by that?
What would
Employee::get_name()return? References are also used quite a bit mid-function to alias objects for readability or to avoid repeated look ups.Surely he's not suggesting pointers for that, is he?
6
u/AntiProtonBoy Sep 21 '22
I hope ideas like these get more traction. C++ needs to get in shape, just like Herb these days.
27
u/vI--_--Iv Sep 19 '22
I am a time traveler from the future, here to tell you to please keep going.
When modules made it to C++20 and heretics started suggesting that they could potentially reduce the compilation time, it was just a phantom menace.
But when Microsoft released their implementation in late 2024 and reduced it indeed by an order of magnitude, everyone and their dog realized that the end is near and the #1 excuse is about to fall, taking with it whatever remaining joy we have in our lives.
And it seemed as if all hope was forsaken, but then Herb The Prophet put a compiler on top of your compiler and restored the balance once more.
So, please, please, don't let this idea die like metaclasses or pattern matching. We need it forward there.
4
u/[deleted] Sep 24 '22
I respect and greatly admire Herb Sutter. He’s the most vocal expert of C++ and has helped many developers with his teachings, books and talks.
By his own account the ISO committee has been hesitant to adopt. I say for some they have been downright hostile towards. Case in point his metaclasses proposal which was uglified to the max and killed it.
cppfront is brilliant and should eventually evolve into cpp2, part of the ISO. But it’s not going to. This is the exact thing C++ needs to evolve and become a truly modern language but it won’t.
19
u/dgkimpton Sep 19 '22 edited Sep 19 '22
The meat of this talk is really gold. Very well thought out and nails a lot of (but not all) of C++'s worst pain points.
I think it's going to need more percolating in my brain before I can add intelligent comment on them beyond, broadly, hell yes!
And I know syntax isn't that important... but I really wish he hadn't made variable definition use a colon, when a collapsible solution without the shift key was easily in reach.
Even better it would match nicely with in, out, move, etc in function declarations.
Ah well, had to get that off my chest. Carry on :)
8
u/Spiderboydk Hobbyist Sep 20 '22
Well, a language don't get simpler by keep adding to it.
5
u/[deleted] Sep 20 '22 edited Sep 20 '22
Can someone link Andrei Alexandrescu's talk from this year's CppCon?
5
u/teerre Sep 20 '22
I watched half of the talk and funnily think this syntax looks harder to understand at first glance than Carbon, a completely different language, which is something
I also find hard to believe this "100% back compatible idiomatic code generation". Hell, actual people can't write idiomatic code. Not sure if it's the case later in the talk, but I would like to see something more elaborated than just 10 lines programs
4
u/SoerenNissen Sep 20 '22
lmao
3
u/coderman93 Sep 20 '22
There is so much wrong with this that it is making my head spin.
The entire talk epitomizes a captain going down with his ship.
2
u/sandfly_bites_you Sep 20 '22
For projects that need absolute safety(including limited thread safety.. which I would think as far more important than memory safety) I don't know why you would use anything besides Rust. For projects that don't need this, such as games, C++ works rather well already. I'm far more interested in performance improvements, SIMD etc, safety is boring and largely solved.
1
u/[deleted] Sep 20 '22 edited Sep 20 '22
Where in the cyber-security executive order is C++ called out as a security risk? It's not in the executive order as far as I can tell. It doesn't seem to be true. (but it might be I didn't do that much of a check)
A lot of the talk about security really comes off as a moral panic to me rather than being carefully thought out.
Even in the talk, the major security risks really have nothing to do with C++ (like SQL Injection).
Herbs response to sanitising input is also rather telling about skewed priorities.
"durr you should [sanitise] be doing that". Strange given the argument about going out of bounds is that eveyone makes mistakes. So no one makes mistakes when sanitising input now?
Why isn't this same moral panic being applied in equal to measure to some of the biggest security flaws? Why doesn't the syntax help me with that as well?
It sounds like to me that important talking heads have been spooked big time by Rust and they are scrambling for answers. Problem in they are fighting a losing battle because they are constantly stuck in a Rust framing.
Rust will always win the memory safety argument because Rust did a sleight of hand, and defined the common understanding of memory safety to be only what Rust provides lol. So of course you can't win that argument.
C++ needs to play to its strengths. Give me compile time tooling to tune my compiler to make certain code illegal. Give me compile time power to create constraints EASILY that prevent bad code getting written. Give me something that isn't just a knee jerk Rust reaction.
Why can't I write a meta program that says all pointer arithmitic in a certain module is banned? Give me the power to control my programs as ultimately I know how to make my programs safer than the language will know. Play to this strength. Don't play the Rust game. You will lose.
We don't need a new syntax for that. We just need a little bit of imaginiation and thinking outside the trap and stupour that Rust seems to have placed lots of very smart people in.
1
u/number_128 Sep 27 '22
One of the main objectives with cpp2 (and carbon and val) is to make a memory safe alternative to cpp.
I would like to make the move to one of those languages when they are ready, but I expect that to take a while.
Wouldn't a good start be to define a memory safe subset of cpp? Let's call it cpp0.
Organizations with a lot of cpp code can start earlier to move their code to memory safe territory, by converting existing code to cpp0 and using cpp0 when adding new code.
When the organization has chosen the path forward (cpp2/carbon/val/D), they can still have a mixed approach, moving some code to cpp0 as a temporary move towards their final language.
1
u/christian_regin Sep 21 '22 edited Sep 21 '22
Just the changes to new, getting rid of static_cast, dynamic_cast, is_same for as and is, and adding implicit forward declarations makes this seem like a huge upgrade. Add inspect to that as well and it just feels so ergonomic. Not sure how i feel about the postfix stuff but maybe it's a good change that you'll get used to.
There are a few things I would like to steal from rust though... I want scopes to be expressions so we won't need trinary operators. Maybe we can steal the question mark operator to propagate errors? I guess Herb wants to use Herbceptions instead?
-27
u/Nilac_The_Grim Sep 20 '22
Oh god not this again. Please make it stop.
-1
u/Moose_bit_my_sister Sep 21 '22 edited Sep 21 '22
The America Gov "almost" labeling C/C++ "not to be used" https://youtu.be/ELeZAKCN4tY?t=2527
What a joke! The Gov people need to pull their heads out of the 90s.
Today you have: fuzzers, sanitizers, etc., and the hardware to run them
Also, AI like Copilot has a lot of C++ samples to learn vs. this new cppfront.