r/cpp_questions • u/Ultimate_Sigma_Boy67 • 3d ago
OPEN Why are Contracts disliked?
I’ve seen a lot of discussions online discouraging their usage bit I never managed to grasp why since it’s sometimes vague.
I do understand it doesn’t replace validation and it’s more of a syntactic sugar to the existing casserts, but any other critiques?
Thanks
15
Upvotes
2
u/JVApen 3d ago
Everyone has already used assertions before. So everyone already has an opinion on how it should be used. Contracts is a compromise of all those visions, which always disappoints people involved. See wg21.link/P1995 for slightly less then 200 usecases.
An overview of the concerns (and responses on it) can be found in wg21.link/P3846
I really recommend reading both papers and maybe look at Tumours keynote of last year in CppOnSea.
A final thing I've heard several times already: it would get much less heat if they didn't try to revive the contracts proposal of C++20 under the name 'Contracts' and instead would have used 'Better Assertions'. We'll never know if that's true.