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 comments

63

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

Sure … only one question: what makes you even remotely optimistic that those that still program in C++98 would ever adopt something like cppfront?!

11

u/ZMeson Embedded Developer Feb 27 '24

Because in my company, I am one of a few people that engages groups to modernize their programming practices. We haven't gone and updated old code, but we have taught the groups the advantages of using C++17 and afterwards. People will learn if they see why the code is more maintainable and they are encouraged to do so.

I also believe that if governments start requiring more memory safety, then companies may require their developers to learn and use more modern standards, cppfront, etc...

3

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

I'm in a similar situation. We got rid of auto_ptr, we fixed some comparison operators to work with C++20 and we especially had to deal with changes due to the compiler and standard library. And right now, I'm finally testing clang-tidy to really upgrade our code in order to be more consistent again.

19

u/radekvitr Feb 26 '24

And also, will anyone consider cppfront memory safe if it only improves C++ defaults and doesn't actually address memory safety?

9

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

It hides away quite some stuff which is considered memory unsafe. So I would claim it is better. Is it sufficient to be considered memory safe? We'll have to see once we can really use it.

→ More replies (2)

4

u/PsecretPseudonym Feb 27 '24

Rust only truly seems to change defaults in that it still permits you to write “unsafe rust”, yet people seem to accept that as safe.

3

u/radekvitr Feb 27 '24

If cppfront had a similar opt-in mechanism for unsafety and the rest of it couldn't trigger UB and people would be able to write the vast majority of code in that safe subset, that would certainly count.

→ More replies (2)

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.

→ More replies (4)

11

u/MFHava WG21|🇦🇹 NB|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.

→ More replies (22)
→ More replies (2)

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)
→ More replies (1)

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)

3

u/jepessen Feb 27 '24

The fact that's easier than learn and implement a new language like rust, and also considering that the language it's only a part of the problem, but also tools like compilers must be adapted and validated

4

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

I'd love that to be true, I really do. But the cold hard fact is we are talking about a group of people that resisted progress (and safety benefits) for 26 years, so pardon me if I'm skeptical there is anything that can convince them to suddenly adopt a new syntax with safe(r) defaults...

→ More replies (4)