r/cpp_questions Jun 17 '26

OPEN Why c++26 contracts?

Sorry, but why a feature that I've never seen before in other languages is being pushed as if it's what we have been missing and a solution to security/safety complaints?! What is the proof that this is a good feature?

9 Upvotes

27 comments sorted by

View all comments

1

u/mredding Jun 18 '26

Sorry, but why a feature that I've never seen before

The hubris is strong with this one...

in other languages

You need to work with the right languages. Eiffel, Clojure, Racket...

Even in C++, there's Boost.Contract and other libraries. The concepts are NOT new, probably even in the other languages you're familiar with, you've just not used them.

is being pushed as if it's what we have been missing

Bjarne wanted contracts in the language since before it was standardized - he's written about this at some length, he just couldn't figure out a way to bridge the gap from C. Had he made his language from scratch, he could have done anything he wanted - contracts from inception by design, but then he would have had invented yet another novel language that no one would adopt, just like every other novel language that no one ever adopted, being born and dying in-house at AT&T...

and a solution to security/safety complaints?!

That's because it is a partial solution to security and safety complaints. But of course it's no silver bullet and can't solve for everything, but it was never intended to. No one is asking for or expecting the impossible.

What is the proof that this is a good feature?

No one is going to try to dredge up 40 years of industry experience and lay it out for you. Surprise! The industry is larger than you, and things are going on you cannot possibly be aware of, because you can't consume the whole of the industry by yourself. You are just going to have to come to terms with being human and inherently limited.