Top
Best
New

Posted by thatxliner 4 hours ago

C++26 Disapproved(andreasfertig.com)
142 points | 57 comments
jandrewrogers 1 hour ago|
As someone who writes high-reliability C++ but is completely outside the standards process, I see the issues with C++ Contracts. It isn’t clear that it solves a problem that anyone has in real codebases, especially after C++20 concepts.

If you were already writing high-reliability C++ then the benefits are difficult to quantify. If you weren’t writing high-reliability C++ then it saves you almost nothing over doing the standard idioms of high-reliability C++ that were already available to you at very marginally more cost. It does standardize expression of it in narrow cases but the payoff seems minimal.

Most of what C++ Contracts delivers is a mashup of what you can already do with constexpr and C++20 Concepts. I like reliability features but this feature, as delivered, looks fairly useless if you already use reliability features. A compelling standard would need to make much deeper guarantees out of the box. And the compiler can already see through most compositions of constexpr and C++20 concepts, which is already very expressive.

C++ Contracts looks a bit like a feature that was designed long before current standard features existed.

drivebyhooting 58 minutes ago||
Your comment just made me realize contracts is different from concepts (which are basically bounded genetics, right…?)
jandrewrogers 37 minutes ago|||
C++ concepts evaluate the properties of types at compile-time. You can inject arbitrary constraints on type properties anywhere in the code including conditional codegen. It is a way of asking if a type “can express this complex set of abstract things or has this enumerated set of properties” with almost arbitrary detail. They are extremely powerful in terms of expressiveness and specialization of code. Insanely good for performance and reliability engineering.

One of the best features to be added to C++ in many years.

C++ contracts are an attempt to bring C asserts into the C++ age. The weakness of C++ contracts is that they are mostly syntactic sugar over C asserts. If you really care about this type of thing, you probably already have a custom C++ assertion framework that is at least as nuanced if not more.

The promise of C++ contracts is that they can aid formal verification, which would be great. As delivered, it can’t do much more than was already possible, which will inhibit adoption.

AlotOfReading 19 minutes ago||

    The weakness of C++ contracts is that they are mostly syntactic sugar over C asserts. 
The sugar is actually one of my issues with them. The evaluation semantics are much more complicated / potentially slower than C asserts because of the sugar, and why you would have to pay those costs isn't obvious at first glance. Lisa Lippincott's excellent talk on the design of contracts [0] is what switched me from a sort of neutral support to disliking it. I think it's a stupid place for the national bodies to draw the line though. std::regex is acceptable, but a nothingburger like contracts tanks the vote?

[0] https://www.youtube.com/watch?v=yhhSW-FSWkE

jandrewrogers 13 minutes ago||
To be clear, I have a lot of issues with the contracts proposal. I probably wouldn’t use despite living out on the standards frontier. I don’t even use C asserts already because they are not expressive enough in important ways. This proposal kind of reifies the inadequacies.

I think the risk is that C++ contracts become an evolutionary dead-end that hang around forever in code bases because they were standardized. It wouldn’t be the first time this has happened.

YuechenLi 2 minutes ago||||
A concept is a compile time requirement that bounds templates which are the generics in C++, so you are close.
stingraycharles 53 minutes ago||||
Concepts are evaluated compile time and make a lot of TMP more elegant. Contracts are runtime check, akin to assertions.

Phrased differently, contracts are to concepts what assert is to static_assert.

rramadass 42 minutes ago|||
Concepts are for Types at compile time while Contracts are for Values at runtime.
quotemstr 50 minutes ago||
Huh? Concepts are types of types. Contracts are fancier, structured runtime assertions. What does one have to do with the other? They're nothing alike.
taybin 13 minutes ago|||
They both start with the letter C, have two syllables, and have/had a hard time getting into the standard. If you’re not paying close attention, it’s easy to get them confused.
jandrewrogers 28 minutes ago||||
That’s exactly my point.

Contracts notionally offer the ability to lift some runtime assertions to compile-time. That is how it was sold. Except they don’t in practice.

Meanwhile, concepts + constexpr if used artfully deliver that in practice, including for many cases that contracts were supposed to solve.

I push all verification to compile-time to the extent possible.

rramadass 40 minutes ago|||
Absolutely Right! - https://news.ycombinator.com/item?id=50361435
LugosFergus 1 hour ago||
I get why some folks would like to see contracts in the language, but C++ is also buckling due to the shear complexity that's getting tacked on to it. I'd rather see more proposals such as C++26's "erroneous behavior" that attempts to reign in the language's shortcomings.
airstrafer 1 hour ago|
Agree. There's an argument that Contracts reduces the complexity of using the language because it offers a more readable alternative to template metaprogramming (also, it has better error messages). But the argument really falls apart when you review WG21's track record for other features.

Like for example, Coroutines were billed as an easier way to write concurrent code, but personally I think it completely failed and ended up being hopelessly complex and confusing. Modules are the same - superficially they make things simpler, but when people actually go to adopt it, the details are so complex that nobody bothers.

skrrtww 1 hour ago||
Personally I'd like to see C++ chill out on new features and maybe sort out the shitshow that is char8_t and std::filesystem.
Krutonium 57 minutes ago|
Maybe a slightly faster std::regex or whatever it's called; apparently it's horrendously slow for no benefit.
ameliaquining 11 minutes ago|||
The primary reason this hasn't happened is that it'd break C++'s de facto stable ABI (even though officially there's no such thing). For a lot more context, see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p20... and https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p18....

Spoiler alert: The option described as "the sort of leadership failing that I pray we can avoid" is what ended up happening.

stingraycharles 53 minutes ago|||
Ranges need work as well, there’s lot of opportunity to improve things there.
jdw64 2 minutes ago||
But I'm curious—why did DIS fail this time with C++26? Weren't feature additions in C++ usually plentiful?

But they say this is the first case where a DIS failed during the standardization consensus process. Why is that?

imaginit 54 minutes ago||
> contracts. Put simply, a number of NBs believe that this feature is not yet ready for release.

The ISO National Bodies voted wisely. C++ has had so many ill defined features over the decades and they wanted to avoid yet another one.

I don't have any skin in the game. I've stayed with the C++11 feature set.

aldanor 28 minutes ago||
Approval of runtime failures essentially failed at runtime
nukanse 34 minutes ago||
C++ should focus into turning SIMD into a higher level language instead of being a giant collection of intrinsics. Avx code is unreadable.
jandrewrogers 23 minutes ago|
SIMD cannot be solved at the compiler level. The capabilities of silicon SIMD implementations are fundamentally so disjoint that code using SIMD requires contextual and platform-specific data structures and algorithms.

SIMD on different silicon is incompatible at layers of abstraction far above the codegen manipulation a compiler can do.

zamadatix 4 minutes ago||
You'll never get the full feature set of all SIMD implementations in a single generic abstraction but I'm not sure that's the only way a SIMD abstraction could provide value. There is a pretty consistent set of narrow SIMD that behaves close enough to consistently get better performance across generic targets with high level abstractions better than auto vectorized scalar code but worse than platform tuned SIMD.
wahern 1 hour ago||
Correct me if I'm wrong, because I don't follow C++ very closely, but based on previous discussions on HN, the opposition paper obliquely referenced in the blog post was presumably Bjarne Stroustrup's, who IIRC had already said he would work behind the scenes to make sure the final pro forma vote to standardize C++26 would fail.
Maxatar 54 minutes ago|
Yes that's right, and from following some threads on reddit about this, he used some really dirty tactics to get it to fail, like scheduling certain snap elections to happen with very short notice at times of the day when people who would oppose his point of view would likely be asleep.
zugi 17 minutes ago|||
Reddit is a cesspool, I wouldn't put faith in anything you read there.

There were no "dirty tricks". The C++ standards committee works by a vaguely defined "consensus", which requires more than "the majority rules". Contracts got added to the C++26 draft. Then there was consensus that Contracts needed to be fixed, but they could never get consensus on any particular fix. So they cruised along relatively unchanged.

In the end, the only way to NOT accept a marginal Contracts feature was to vote down the full language spec. Now they'll regroup and decide how to proceed.

adzm 36 minutes ago|||
So is he a hero, or villain? Does it all come down to concepts?
afdbcreid 9 minutes ago||
Not concepts, contracts.
hankbond 1 hour ago||
Maybe my reading comprehension has just nosedived but I could not find where this article discusses what the heck Contracts refers to?
AlotOfReading 1 hour ago||
You'll find plenty of info if you search for anything like "c++ contracts" [0], but the short of it is that they're just pre/post conditions on functions. Slightly improved assertions, basically.

[0] https://en.cppreference.com/cpp/language/contracts

btown 1 hour ago||
https://www.cppstories.com/2026/cpp26_contracts/ is IMO a better introduction.

cppreference is often a bit too technical for its own good :)

But I think there's a broader issue which is that if it took me multiple searches to find a good-enough visual "pitch" for what contracts look like in practice, its champions have not yet won hearts and minds - which brings us to the situation at hand.

bionhoward 59 minutes ago||
Oh im not a c++ guy but that actually looks pretty awesome because it’s like Hoare logic
SolarNet 1 hour ago||
Its a very inside baseball article. Contracts is a proposed C++ language feature for improving programmable assertions of program state. E.g. a better c++ version of C's assert function. That in theory will improve both safety and performance by letting people add more complex assertions (e.g. pre/post conditions) to functions.
youre-wrong3 1 hour ago|
[dead]
More comments...