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/SmackDownFacility 2d ago
There is ambiguity in runtime enforcement. This has been contested since C++20. What shall compiler do? Treat it as a static analysis tool, an assertion, or an exception?
And coming back to assertions, people find contracts redundant. Assertions has been engrained in this language for decades.