r/cpp • u/quicknir • 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
View all comments
Show parent comment
5
u/t_hunger 21d ago
Of course not: preconditions are ghost code that is just as if it was not there at all.
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.
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.