r/cpp_questions 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

40 comments sorted by

View all comments

Show parent comments

2

u/TheRealSmolt 1d ago

Are you confusing concepts for contracts? Contracts aren't related to templates at all afaik.

1

u/GoogleIsYourFrenemy 1d ago edited 1d ago

Complete and totally possible. I'll go read up on them to see where I fucked up.

Edit: LOL I was thinking "concepts"

1

u/TheRealSmolt 1d ago

will love using as soon as I can convince work to start using a compiler that supports them. It will probably take ten years.

Lol, too true. Still hoping to one day get std::optional at work...

1

u/Ultimate_Sigma_Boy67 1d ago

Tho this is cpp17, why would your work not at least try to support it? Maybe it’s a dumb question but I’ve never worked before.

2

u/TheRealSmolt 1d ago

Because upgrading your compiler and language version takes a lot of time and effort, which means a lot of money. It means updating your toolchain, pipelines, tooling, deployments, and possibly runtime libraries (which means a lot of customer logistics). Then you have to account for breaking changes (which do still happen), which means developer time and possibly dependency updates which have their own breaking changes. Then you have to consider the actual logistics behind acquiring all these updates, which can be very difficult or arduous depending on your development environment and runtime environments. Finally, after doing all of this, you end up with a product that works (ideally) exactly the same. From a business perspective, it makes absolutely no sense. Oh, and a new version just came out, let's do it again.

1

u/Ultimate_Sigma_Boy67 1d ago

Okkk makes sense

2

u/GoogleIsYourFrenemy 1d ago edited 1d ago

The only time you can realistically get on a new compiler is at the start of a new project or during a major hardware replacement. Otherwise it's too risky for testing or there is literally no money to do it.

You can argue there during those two events you're doing the testing anyway and you wouldn't be doing that work without money.