News for hackers. Stuff that matters.
Re:C++26 Disapproved by throwaway2037 on Wednesday November 04, 2026 @02:45AM (#50362512)

    > high-reliability
I never heard this term used with C++ before. Can you explain more? Ideally: Can you give an example snip of code that demonstrates it clearly?
Re:C++26 Disapproved by arein3 on Wednesday November 04, 2026 @03:23AM (#50362753)
Its a set of rules, used by defense software, they are available on the internet
Re:C++26 Disapproved by NSUserDefaults on Wednesday November 04, 2026 @03:55AM (#50362967)
For example the failed F-35 project used it. Seems pretentious and risky compared to using a language that is safe by default.
Re:C++26 Disapproved by amelius on Wednesday November 04, 2026 @04:01AM (#50363015)
> compared to a language that is safe by default.

This also sounds pretentious ...

Re:C++26 Disapproved by NSUserDefaults on Wednesday November 04, 2026 @04:14AM (#50363081)
Because you think there is no such language, or even one that gets closer than C++? Look I still kind of like C++… for games. I would never put it in a fighter jet for gods sake.
Re:C++26 Disapproved by fps-hero on Wednesday November 04, 2026 @05:03AM (#50363407)
I don’t want to be inflammatory, so let’s stick to facts. The F35 is the manifestation of a test aircraft designed in the 90s. Of that era, software was predominantly single threaded, hardware definitely so. They also weren’t using the latest and greatest of hardware at the time, they opted for proven flight platforms with hardware dating back well back into the decade. So, very lacklustre performance, tight memory constraints.

The only other legitimate choice for writing software at the time would have been ADA, which for some reason never took off despite being purpose build for the application. Of that time, C++ was the new hotness, it was popular, it was solving architectural problems, and it was performant, unlike say Java.

It’s fairly naive to say “I’d never use C++”. The C++ programmers of the time would have looked at Fortran or COBOL with the same level of disdain. We are lucky to live in a time of better options, and the impending post code future.

Re:C++26 Disapproved by tialaramex on Wednesday November 04, 2026 @05:43AM (#50363715)
> The only other legitimate choice for writing software at the time would have been ADA

Ada makes a lot more sense for this work than C++ did twenty years ago.

Re:C++26 Disapproved by bluGill on Wednesday November 04, 2026 @08:59AM (#50365598)
Ada didn't make sense either: nobody wanted to learn it.
Re:C++26 Disapproved by SolarNet on Wednesday November 04, 2026 @10:50AM (#50367324)
There were schools of computer science, accredited universities, that taught it heavily (one of the 3 lab intro to programming languages next to c++ and python, and allowed to be used through the entire program at mine). A 1/3 of graduates of some of these places got jobs in it, because they were reliable and well paying jobs.

And then the industry swapped to C++. This was not a DoD mandate, this was companies like boeing trying to pay their engineers 1/3 to 1/2 less by paying for C++ devs (starting salary for ada devs was 90-140k, starting salary for c++ devs was 60-180k according to exit statistics). They of course eventually learned that good C++ devs are actually more expensive than their old Ada ones. Not that they bothered to hire good c++ devs.

Re:C++26 Disapproved by pjmlp on Wednesday November 04, 2026 @11:39AM (#50368120)
Yes we did, the major impediment was the price of available compilers, their dependency on UNIX workstations, where the Ada compiler was extra, on top of C and C++ that were already there.
Re:C++26 Disapproved by Maxatar on Wednesday November 04, 2026 @02:17PM (#50370233)
No it wasn't that nobody wanted to learn it, it's that back then Ada developers cost a lot more than C++ developers and businesses didn't want to pay them.
Re:C++26 Disapproved by drysine on Wednesday November 04, 2026 @05:55AM (#50363803)
>it [C++] was solving architectural problems

What do you mean?

Re:C++26 Disapproved by fps-hero on Friday November 06, 2026 @08:57AM (#50392352)
Think about the difference in how you would structure a program if it was coded in C++/Java vs C. C++ was an enabler of object oriented programming.
Re:C++26 Disapproved by drysine on Friday November 06, 2026 @04:27PM (#50398759)
About the same, I think)
Re:C++26 Disapproved by fps-hero on Sunday November 08, 2026 @08:39AM (#50413262)
I think what is obvious now wasn’t obvious then. If you think about how Linux and the open source community rallied around C, this was at complete odds to what was being taught at a university level. It’s a miracle C survived (if I only through new C++ programmers thoroughly rejecting its promise and sticking to “safe C++”). Even still, rust is a solution to memory lifetime problems with a modern toolset, it’s not solving ergonomic problems which is how you attract new developers. Similarly, ADA was a better language, probably pascal too, they didn’t win.
Re:C++26 Disapproved by NSUserDefaults on Wednesday November 04, 2026 @06:29AM (#50364145)
“Let’s use the new hotness for this new fighter plane” maybe puts things into perspective for me.
Re:C++26 Disapproved by Cthulhu_ on Wednesday November 04, 2026 @04:19AM (#50363098)
[delayed]
Re:C++26 Disapproved by tialaramex on Wednesday November 04, 2026 @04:55AM (#50363326)
C++ is a pre-standard "Eh, just do whatever" language in 1993.

Bjarne's 2005 JSF rules have the same effect as an "Employees must wash hands" sign. It's not the billion dollar fast food chain's fault that a minimum wage employee didn't obey the sign and now you've got food-borne illness. They put a sign up!

Re:C++26 Disapproved by pjmlp on Wednesday November 04, 2026 @11:37AM (#50368092)
He always misses the amount of avionics bugs that the F-35 suffered from, in spite of the rules.
Re:C++26 Disapproved by LiamPowell on Wednesday November 04, 2026 @05:40AM (#50363691)
The incredibly obvious answer is Ada, given the DoD commissioned it and the fact that it was used for the F-22.
Re:C++26 Disapproved by fpoling on Wednesday November 04, 2026 @07:16AM (#50364545)
I wonder if DoD desire to tap into a bigger pool of C++ programmers also brought a lot of people who was not trained to write a high-reliability code.
Re:C++26 Disapproved by SolarNet on Wednesday November 04, 2026 @10:57AM (#50367443)
Ada is far safer than Rust (not in edge case memory allocation problems, but in day to day application programming), and not only existed at the time, it was the industry standard for aviation (for good reason). Entire educational programs and pipelines existed for it.

Boeing and other defense contractors dropped it because C++ programmers were cheaper on paper (not realizing/caring that good C++ engineers were more expensive).

Re:C++26 Disapproved by cestith on Wednesday November 04, 2026 @12:49PM (#50369051)
One of my current coworkers used to work on on-board systems for military aircraft. Anecdotally he tells me the critical systems for the ones he worked on were Ada but other systems could be C++.
Re:C++26 Disapproved by AnimalMuppet on Wednesday November 04, 2026 @09:20AM (#50365900)
In what sense was the F-35 project a failure?
Re:C++26 Disapproved by pjmlp on Wednesday November 04, 2026 @11:43AM (#50368175)
Total cost due to avionics issues and other construction failures.
Re:C++26 Disapproved by rerdavies on Wednesday November 04, 2026 @03:09PM (#50370828)
[delayed]
Re:C++26 Disapproved by throwaway2037 on Thursday November 05, 2026 @05:35PM (#50385479)
Has there ever been a modern fighter jet built in the last 50 years that wasn't consider in one aspect or another an "failure"? At this point, the term "failure" seems almost pointless to describe very large, nation state projects that are heavily used and have thousands built.
Re:C++26 Disapproved by fps-hero on Saturday November 07, 2026 @06:39AM (#50403661)
Whether the F35 was a failure depends on whether you are looking out your forward window, or rear view mirror, and when you were looking.

The F35 program certainly seemed like a white elephant, until it crossed the threshold into production and wasn’t. It was a massively delayed cost blowout project, which has turned into a huge success.

Re:C++26 Disapproved by AdamN on Wednesday November 04, 2026 @09:45AM (#50366245)
Username checks out :-)
Re:C++26 Disapproved by weitendorf on Wednesday November 04, 2026 @05:03AM (#50363402)
I think you're thinking of https://en.wikipedia.org/wiki/High_Integrity_C%2B%2B

I wrote a comment explaining what in my mind distinguishes "high reliability" (defensive programming and making invariants/error cases/intended use explicit) C++ from regular C++. IMO it basically boils down to contemporary "Google/fintech style C++", which is a different development culture and ecosystem from defense/automotive

Re:C++26 Disapproved by fpoling on Wednesday November 04, 2026 @07:19AM (#50364573)
The biggest split is not using exceptions with aborts on memory overflow. It alters the programming style to such extent that it feels like a different language.
Re:C++26 Disapproved by zaphirplane on Wednesday November 04, 2026 @03:57AM (#50362984)
[delayed]
Re:C++26 Disapproved by Rexxar on Wednesday November 04, 2026 @05:55AM (#50363806)
Google give enormous priority to new content, especially on very well referenced and active sites like HN. So it probably doesn't mean as much as you think.
Re:C++26 Disapproved by Maxatar on Wednesday November 04, 2026 @02:14PM (#50370191)
I can search for many technical terms that have recently been posted to HN and it and appear in the comments and it won't come up on the front-page, let alone the first two items.
Re:C++26 Disapproved by weitendorf on Wednesday November 04, 2026 @04:18AM (#50363095)
Assuming the original commenter is referring to essentially best-practices defensive C++ like you see at Google and some projects like Envoy proxy, and the other reply is thinking of high integrity C++ [0] (a proper noun form of C++, whereas just writing reliable C++ is less proscriptive):

Here's an example that uses compile time type assertions (static_assert, C++ can already do this), runtime errors (CHECK, standard Google/abseil practice for explicitly handling invalid states and invariants), test/dev checks (more of a defensive programming inline test than a pre or post condition), and wrapper/error handling types to do the same kinds of things as you might think to use contracts for.

  template <typename T>
  absl::StatusOr<double> Percentile(std::span<const T> sorted_values, double p) {
    static_assert(std::is_arithmetic_v<T>, "T must be numeric");
    CHECK(p >= 0.0 && p <= 100.0) << "p out of range: " << p;
    DCHECK(std::ranges::is_sorted(sorted_values)) << "input not sorted";

    if (sorted_values.empty()) {
      return absl::InvalidArgumentError("empty input");
    }

    const std::size_t last = sorted_values.size() - 1;
    const double rank = p / 100.0 * last;
    const auto lo = static_cast<std::size_t>(rank);
    const std::size_t hi = std::min(lo + 1, last);
    const double result = std::lerp<double>(sorted_values[lo], sorted_values[hi],
                                          rank - lo);

    DCHECK(result >= sorted_values.front() && result <= sorted_values.back());
    return result;
  }
Before I was exposed to this style of C++ and learned to write it this way, it basically felt like a different language. You often hear people say that the C++ standards committee and language designers seem to have different priorities and developer culture vs most big tech companies/finance and I think it's because even if they're aware of the features and tools that come out of Google (et al) [1], they don't use them in their current day to day jobs and want that functionality in the core C++ toolchain.

IMO the problem is that a lot of what they want to add to the language is already "solved" by third party tooling, but because for whatever reason they don't use those existing solutions as part of their everyday work, they sometimes come up with language features that overcomplicate or solve the wrong thing, in a way that you would intuitively understand if you were already regularly using 3P tools to solve them.

I could also be the one misinterpreting things here so apologies if this is obvious or not what the original commenter meant by "high reliability".

[0] https://en.wikipedia.org/wiki/High_Integrity_C%2B%2B

[1] https://abseil.io/about/ is one of many third party ways to make C++ less insane

Re:C++26 Disapproved by pedro_caetano on Wednesday November 04, 2026 @05:19AM (#50363512)
If you squint hard enough your example does look a lot like Ada pre and post condition contracts (perhaps a bit less ergonomic, at least for someone who hasn't written C++ in a while).

At this point the rust contracts crate with `require` `ensure` look like a more straightforward approximation of Ada's Contracts and assertion policy. But still as far as I am aware no one has implemented something that mimics the static proof functionality in Ada's SPARK subset (which arguably not all applications or problem domains actually need or can justify the extra effort/cost).

Re:C++26 Disapproved by rramadass on Wednesday November 04, 2026 @07:49AM (#50364838)
> IMO, a lot of what they want to add is already "solved" by third party tooling,

https://news.ycombinator.com/item?id=50364593

Re:C++26 Disapproved by weitendorf on Wednesday November 04, 2026 @09:11AM (#50365783)
I haven't seen any good examples of contract preconditions that I would actually want to use. What I've seen is stuff like

  double safe_sqrt(double x)
    pre(x >= 0.0)
    post(r: r >= 0.0)
  {
    return std::sqrt(x);
  }
Preconditions violate the principle of "make invalid types unrepresentable" but look like they're helping. They are basically a oneoff extra specific type that (if the state you're checking is worth checking at all, it must be representable in the actual argument's type) contradicts the actual argument's type. So why not change the argument's type directly?

Because it's hard, or not possible, for the same reason that most of these preconditions aren't generally statically verifiable.

Suppose your precondition is x > 5. Statically, you can stop someone from directly passing a literal <= 5, detect locally declared variables assigned to numeric literals and do the same. But to generally infer whether any argument satisfies specific properties quickly gets extremely complicated, because how can you generally verify that the calculations done to a const or literal within the caller's scope guarantee certain properties about the output, without actually performing the calculation? You can come up with cases where you only add to an int and you see it was initialized to 0, so you know it's never < 0 barring underflow. Those are the easy cases

If the caller is passing in something derived from their own arguments, or from I/O, all bets are off. All you know is that the argument has a type, and its value was derived from unknown inputs. So you need a runtime check to actually assert your precondition and make it behave like a type check. But then what happens if input doesn't meet the precondition? Do you throw an exception or crash?

I think that there should be a reference implementation for a useful static analyzer for preconditions, for it to be added to the language. Obviously it would be nice if you could verify that callers only pass in x > 5 to your function, but I think deferring the semantics for contracts to however the build/compiler chooses to handle them (because they might, one day) is not good enough for adding a new feature and syntax to a language. If preconditions can be used for useful static analysis beyond what static asserts and the type system gets you already, there should be evidence for that. I'm skeptical that you can do any better than a regular static assertion/type checks.

Also, I do think the lack of explicit handling (if in practice preconditions are only generally evaluable at runtime) in the contracts syntax is bad. The proposed syntax looks too much like a type or static assertion for a runtime check (note that you can easily see what CHECK/DCHECK macros actually do just by clicking through to their definition). And if it isn't in practice just a runtime check, there should be proof!

Re:C++26 Disapproved by William_BB on Wednesday November 04, 2026 @09:48AM (#50366284)
> If the caller is passing in something derived from their own arguments, or from I/O, all bets are off.

This is the part of contracts that I don't understand. I suppose you could (1) runtime validate any user input to the program and then (2) chain multiple functions like `safe_sqrt` that provide pre and post conditions.

In theory, this should allow the static analyzer to reason about any arbitrary input. However, this to me raises even more questions: is this practical, is this possible and why would I not try to achieve the same through types ("make invalid types unrepresentable"). Maybe I'm completely off the mark here.

Re:C++26 Disapproved by weitendorf on Wednesday November 04, 2026 @01:53PM (#50369913)
No I completely agree. I think it is almost a deus ex machina/wishful thinking where people wish type systems could handle invariants like this, and know at least some invariants should be easy to enforce statically, but haven't seriously considered whether all invariants generally can be feasibly statically verified at buildtime.

If they can't, then it is IMO a mistake for the language to make contracts declarative (like types), or to think of the static checks as anything more than something extra on top of what is actually a runtime check. And if they can, then why are they not just types?

Re:C++26 Disapproved by rramadass on Thursday November 05, 2026 @12:30AM (#50375573)
Nice. However, you are mixing up both sides of the "Curry-Howard Isomorphism" i.e. Set Theory/Predicate Calculus vs. Lambda Calculus/Type Theories.

See also my comments here - https://news.ycombinator.com/item?id=50365641 and https://news.ycombinator.com/item?id=50375318

The idea of a "proof" which is what Symbolic Execution by a Static Analyzer does is different on both sides of the above isomorphism. You cannot mix them indiscriminately. This is because C++ does not have a typing theory (in the sense of lambda calculus derivatives) but simply maps types to sets. Hence one cannot do "Type-Driven Design" natively like a lambda calculus-based language even though you can do aspects of it via explicit programming techniques (eg. see "Functional Programming in C++ by Ivan Cukic").

That is the reason i suspect contracts in C++ moved away from the original focus on static analysis to managed runtime checks + some static analysis. C++26 contracts are firmly in the Set Theory/Predicate Calculus camp and are not integrated into the Type System.

We need an augmentation of the C++ type system and then a narrowing so we can end up with something like Ada-SPARK (call it "Safe C++"/"Profiles"/whatever).

Re:C++26 Disapproved by weitendorf on Saturday November 07, 2026 @12:40AM (#50401965)
I think we are maybe making the same point in opposite directions.

You basically need a complete LEAN-style predicate calculus to generalize guarantees on runtime invariants through compile-time analysis. You are making claims on the interior structure of data that is defined by how many bits of information it encodes, including at the boundary where provenance ends (the arguments passed into your binary are all basically just multiples of 4/8byte enums, ints, strings, or floats), where you'd also need to be able to check/enforce that the data has particular properties, otherwise all you did was introduce more ways to do UB

C++ has nothing close to this in place and it's in fact quite a different claim that any particular invariant is obviously statically verifiable, or that a large class of assertions would be very easy to prove statically, than the claim it would be fine to only catch "most" or even "many" type assertions statically and just handle the rest at runtime.

It's like saying "well 2 + 5 obviously < 10 and most static checks are obvious, so it's better to at least handle that even if we can't statically prove which particular subset of N have 2^N % 10 = N and just check the really hard stuff at runtime". Because that means you have to ask whether any runtime failure is some emergent/adversarially difficult problem from number theory, but at least you can catch all the easy stuff you would have caught anyway

Re:C++26 Disapproved by throwaway2037 on Thursday November 05, 2026 @05:38PM (#50385508)
This is a great reply. Thank you for the code snip. It makes a lot of sense to me now. Basically: You need to have pre-conditions and post-conditions.

In the code sample above, can you explain why DCHECK is used instead of CHECK? I needed to Google to ask about those macros, but it looks like DCHECK is only enabled in debug builds.