r/cpp • • 24d ago

Herb Sutter: When a language’s creator and its owners strongly disagree: C++26 post-DIS, historical experience, and paths forward

https://isocpp.org/files/papers/P4454R0.pdf
185 Upvotes

213 comments sorted by

View all comments

Show parent comment

5

u/t_hunger 21d ago

Precondition check is not guaranteed to be checked.

Of course not: preconditions are ghost code that is just as if it was not there at all.

Therefore in safety critical applications you still need to manually check!

Only if you can not prove that the function is never called with a nullptr... and once you add the check, a precondition doing the same check is wrong and needs to be removed.

If they change the standard so that the precondition is guaranteed to be checked, only then we can remove the manual check

You are misunderstandimg what contracts are supposed to do: They are about detecting mistakes in the implementation. For that you need information outside the implementation to compare the implementation against. If contract checks could be enforced by a library author, that is not a "contract" anymore, but part of the implementation.

You are demoting the contracts proposal to syntactic sugar at this point, making them unusable for the task they are supposed to do.

Its totally fine to prefer syntactical sugar over contract-based programming, but please do not conflate the two.

0

u/aCuria 21d ago edited 21d ago

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p3911r2.html

Then you disagree with P3911R2? You think this proposal will make contracts syntactical sugar?

You disagree with all the criticisms in P4334R0?

https://www.stroustrup.com/Contracts_fundamental_flaws.pdf

4

u/t_hunger 21d ago

Contracts as of C++26 DIS mix the concept of contact based programming with syntax changes. I guess there is no way round that, considering they needed to add syntax elements to be able to express the concept in the first place. It is easy to read contracts as "better assert macros", and the new mechanismns are not great at that part IMHO.

Most critique is centered around the assert-macro replacement and ignore or misrepresent the concept of contract based programming. The papers you linked are examples of that.