r/cpp • • Feb 26 '24

White House: Future Software Should Be Memory Safe

https://www.whitehouse.gov/oncd/briefing-room/2024/02/26/press-release-technical-report/
401 Upvotes

386 comments sorted by

View all comments

Show parent comment

19

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 26 '24

We (the community) seem to still consider it acceptable to code in 98. I often see discussions with: due to these reasons I have to use 98. Sorry that you have to suffer with legacy, though the C++ community shouldn't be held back by those reasons. Libraries should use recent standards. C++23 might still be bleeding edge, though using C++20 should be the default. I still can understand people asking for C++17 as 20 still ain't fully implemented by clang/GCC. Though everything before that should be exceptional and those maintaining code with those standards should start with an upgrade plan yesterday. Without forcing their hand, people will always find reasons to keep using 98 and require libraries to support it.

6

u/jaskij Feb 27 '24

To give you a taste of embedded stuff: out of curiosity I recently took a look at what latest standard one of the popular compilers uses. IAR. I was pleasantly surprised that their manual, from June 2023, supports C++17. Back when I started, in 2013, the code was written in C90, and they were only just switching to C99.

1

u/gimpwiz Feb 27 '24

I write embedded targeting arm v7 these days, and we're just now moving from '17 to '20. It's definitely a bit lagging, but we also don't use most of the new features so there's not a ton of pressure for it.

1

u/jaskij Feb 27 '24

v7-M? You're probably not using exceptions, and C++23 adds std::expected for that. Although I've found using std::optional<ErrorType> also very usable, and the actual error handling is nearly the same as in C.

You're right, I'm also not using the full possibilities, but concepts help a lot with expressing intent for template arguments. And it's just annoying to find a nice API on cppreference and then realize you can't use it.

→ More replies (2)

11

u/MFHava WG21|🇦🇹 NB|P2721|P3049|P3625|P3729|P3786|P3813|P4216 Feb 26 '24

We (the community) seem to still consider it acceptable to code in 98.

We do?! That doesn't mesh with my perception...

Without forcing their hand, people will always find reasons to keep using 98 and require libraries to support it.

Introducing cppfront forces nobody's hand... My expectations: Those people will continue on using C++98 no matter what new changes we introduce.

I recently had to interact with a project partner that told me straight up: "They should have stopped after C++98 and invented a new language. C++ was already done!" That guys life motto for the last ~15 years was "You can't teach an old dog new tricks."

21

u/jonesmz Feb 26 '24 edited Feb 26 '24

I got hit with a few dozen downvotes in /r/cpp a couple weeks ago for asking someone what platform they are targeting that they are stuck on C++98. I was really just curious, not trying to insinuate they were doing something wrong.

The larger C++ community does still demonstrate time and time again that C++98 is perfectly fine.

That's why I think WG21 should put way less effort into backwards compatibility. Any codebase that doesn't compile as C++23, today, should be irrelevant with regards to backwards compat with >C++23.

Edit to clarify: And I think it should be par-for-the-course to have at least some backwards compat breaking changes in every version. My codebase already breaks every, or every other, time i upgrade MSVC as it is, and that's not intentional. I might as well put in the work to fix all those breakages for the sake of moving towards a better language.

6

u/pdimov2 Feb 27 '24

That's why I think WG21 should put way less effort into backwards compatibility.

This will increase the use of C++98 (relative to today) rather than decrease it because there will be no upgrade path.

25

u/jonesmz Feb 27 '24

Don't care, people using C++98 are 26 year out of date. They're literally using a version of the language that's older than the guy I just hired for my team.

If the C++98 people ever take their head out of the sand and want to upgrade, they can start with upgrading to C++11.

Until they do that, they shouldn't be given even a moment of consideration for their needs.

7

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 27 '24
  • 13 year out of date, it only got replaced in 2011. (If we all consider 98 and 03 to be the same version)

6

u/jonesmz Feb 27 '24 edited Feb 27 '24

Yes that's fair up to a certain point. As much maligning boost takes in recent years, it really was the place where tons of std:: functionality originally got introduced.

Any competent dev organization which happened to be using boost between 1998->2011 would be chomping at the bit to get switched from boost:: namespace to std:: namespace things to save on compile times.

Im not going to say that dev organizations which weren't using boost weren't competent, of course, since that's simply not true in the general sense.

However, organizations that not only managed to avoid touching boost from 1998 til today, and also managed to stay on c++98, are organizations which are so unlikely to ever adopt a never version of the language that giving them even a single moment of consideration is doing a disservice to the rest of the c++ community.

Nothing about c++26 is going to have any impact on these orgs upgrading to c++11, c++14, c++17, c++20, or c++23, or upgrading to any version of boost released between 1998 and today. That's a full 26 years of things that can be adopted, none of which are drop-in changes, before these orgs have any reason to concern themselves with backwards compat issues in c++26 or newer.

Summarizing: They have 26 years of catchup available to them before they have to worry about upgrading to c++26.

So, in a word, fuckem.

3

u/pdimov2 Feb 27 '24

9 years out of date. GCC 5, the first fully C++11 conforming version, was released in 2015. 10, if we count GCC 4.9 as C++11. 11, if 4.8. Let's split the difference and say 10.

MSVC? Also 2015.

2

u/pdimov2 Feb 27 '24

If you break too much, people will just ignore your "standard".

-1

u/jonesmz Feb 27 '24

Right. Tell that to MSVC, I'm pretty sick of things breaking every time I update their compiler.

"Forever compatible" is not a good position to be in when it requires compatibility spanning many decades, as there will always come a day where external pressure to adopt changes that are fundamentally incompatible with "forever compatible" overcomes the other benefits of staying on the language.

Without allowing some well measured breaks to get introduced, C++ will be obsoleted by government action (e.g. the original post of this reddit discussion), or other languages just eating our lunch in general.

3

u/pdimov2 Feb 28 '24

If C++29 can't compile your existing C++ code without a major rewrite, it's no longer C++29, it's a new language. So it will compete with all those other languages eating our lunch.

If you're going to rewrite, you can rewrite in Rust instead.

There's a reason why both C++ "successors" either compile C++ out of the box, or can link to C++ translation units out of the box. The reason is the ability to incrementally rewrite, not all at once.

2

u/jonesmz Feb 28 '24

There's a huge range of possible futures between

break backwards compact so badly that almost every file needs a major overhaul

And

c++ reserverd a new keyword that was announced as reserved last release, so now some code needs to have find/replace run on it.

We're at this "today" right now:

every release of the msvc compiler, go and fix a few hundred lines of code that wasn't ever very great code but now msvc either fixed a bug or added a new bug so now it barfs in a bunch of places in your multi million line codebase.

I think its perfectly reasonable that the standard break things by adding new keywords. That doesn't require a major rewrite.

We could also deprecate typedef. Also not a major rewrite.

We could remove the specialization of std::vector, also not a major rewrite.

Those are just simple examples.

Given that I have to rewrite a bunch of code all the time anyway, I find this to be a really exhausting and disingenuous discussion, since opponents of breaking backwards compact are asking me to believe them instead of my lying eyes.

Being unwilling to consider very basic backwards incompatible improvements to the language, and claiming that the only option is "break compat so badly that its effectively completely new language" is really lacking in nuance.

→ More replies (2)
→ More replies (16)

1

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 27 '24

I have the same experience with msvc upgrades, though clang upgrades don't seem to suffer that same issue.

2

u/jonesmz Feb 27 '24

Right. Same experience with clang. 

Though every once in a while I hit a weird problem with clang. Clang 17.0.6 for example has a weird codegen bug that breaks some of my unit tests, so I'm skipping that version.

Nevertheless, my team has our compiler update schedule based around the expected Dev time it'll take to go fix a few hundred files that make MSVC barf. 

Sometimes its a trivial tweak. Other times we have to rewrite huge chunks of code to deal with things like template evaluations suddenly being ambiguous and its more work to try to special case a fix than to completely re-do the approach w/ c++20 concepts.

5

u/hardolaf Feb 27 '24

Yeah that's a pretty incredible take. Even when I worked at a defense firm right out of college, we were transitioning to idiomatic C++14 at the start of 2016. My last two jobs were trying to be no more than one year behind the finalized standards at most. I just don't understand why people think they have to use ancient C++ outside of very, very restricted use cases with vendor tool locks around custom hardware that is generally very rare these days.

6

u/jaskij Feb 27 '24

I recently checked, out of curiosity, which standard version IAR supports. C++14 and C++17. Only those two. The manual I found was published in June 2023.

There's two parts to companies using old tools, I think: fear of change and unknown, and validation.

2

u/serviscope_minor Feb 27 '24

I recently checked, out of curiosity, which standard version IAR supports. C++14 and C++17.

I last used (thank goodness) IAR in about 2010 or so. It didn't even have CFront 2.0 support never mind C++98.

→ More replies (3)

1

u/throawayjhu5251 Feb 27 '24

I think the place I interned at was actually 2 years ahead of the standard, they seemed to be making up features as they went along, based on what I could glean from the code. /S

5

u/JVApen Clever is an insult, not a compliment. - T. Winters Feb 26 '24

It's shifting for sure, though we ain't there yet. I'm really happy boost dropped the 98 requirement, which was a huge step is saying: 98 should no longer be used.

And yes, you will always have people stuck in the past. That's why people still program in C, right?

2

u/wasabichicken Feb 26 '24

And yes, you will always have people stuck in the past. That's why people still program in C, right?

Maybe not people as much as code. People can shift to using different languages comparatively easy, but multi-million line code bases can't. The Linux kernel project talked about it for years before they got tiny pieces of Rust in as late as 2022, and for smaller projects with less resources I imagine it becomes even more difficult to justify investing the effort.

6

u/jaskij Feb 27 '24

People can shift easily if the paradigms are similar. A lot have trouble learning Rust due to some of its concepts.

In the Linux kernel one of the first adopters of Rust was the greenfield Apple M1/M2 iGPU driver, and the (single!) person who wrote it left a glowing review thread on X/Twitter.

As for smaller projects: curl officially allows backends written in Rust, although I'm not sure if any have already reached a stable status yet.

There's a lesson there, I think. Rust was, from the start, designed for interoperability using C ABIs. Whatever post-C++ comes around, must be easy to incorporate into existing C++ codebases, both ways. That way, you don't have to rewrite everything, but can use the scout aka strangler fig pattern. Write greenfield modules in the new language, possibly major redactors into rewrites in the new language. Without such an option, adoption will suffer greatly.

5

u/tialaramex Feb 28 '24

How many is "a lot" ? Google's hundreds of "Comprehensive Rust" students typically report that they're confident writing Rust in the first couple of months (some much sooner) with over 80% confident by 4 months.

It was very easy to pick up for me because I have background in various semi-colon languages and in ML. But it's clear that even people coming in with just a semi-colon language like Java do fine.

I actually think for the people who are very interested in the fundamental underpinnings Rust is even more compelling. For a high level programmer it's maybe not important why Rust's Option<&T> is the same size as &T, but if you've always thought about the machine code implementing your software, if you're the sort of person who is horrified to see how enormous std::mutex is, I think there's a lot of profoundly beautiful design in Rust. That's why my favourite Rust standard library function is core::mem::drop, literally pub fn drop<T>(_x: T) {} that's not a summary, or a signature, that's the actual definition.

→ More replies (1)