r/cpp • • Feb 26 '26

The Joy of C++26 Contracts - Myths, Misconceptions & Defensive Programming - Herb Sutter

https://www.youtube.com/watch?v=oitYvDe4nps&t=1s
73 Upvotes

84 comments sorted by

View all comments

Show parent comment

4

u/germandiago Feb 28 '26 edited Feb 28 '26

Thst is exactly my point that favors this evolution.

You try to deliver a perfect solution that is almost impossible to use vs an incremental solution (that some day could become a single compiler switch, who knows) that covers first 50, 70%. At the end you end up covering 90% and with some coding patterns (for example use values for return types or smart pointers, avoid references). Actually there is even experimental lifetime subsets for clang nowadays that might end up in the standard in an evolutionary way, so let us say you cover 95% of common coding patterns.

A solution like this is lower-cost to apply compared to alternatives, a really good reason for using it for substantial gains.

So the real-life question here would be: which one has more chances to benefit more lines of code in real lofe, all taken into account.

I think there is enough "rewrite your software" experiences in the industry and enough "make next version incompatible" (for example Python 2/3, read Guido). I honestly think it would have been a suicide any path that does not respect:

  1. current codebases   2. cannot be adopted incrementally   3. adoption is as low cost as possible.

Any other thing is just not realistic.

At the end of the road, you will find something that solves most problems in a more "evolutionsry" way that plays smooth enough. The clean split is highly risky: to begin with it throws away a huge knowledge base of how to code in C++ to replace it with an all-new way of programming. Only that alone is a huge cost in resources. But on top of that, incompatible models would call for a new std lib. Why wait for a std lib in each compiler I use if I can just use another language?

So I think this was a correct solution. People often criticize me for this here, but that is what I really think...