News for hackers. Stuff that matters.
Re:Contracts for C++ (DbC) [pdf] by mempko on Thursday November 14, 2024 @10:48AM (#42137388)
Wow, people miss the point of contracts. You never want to turn them off in production, because that's where all the weird shit happens that you never thought of. Contracts catch bugs in those times. Maybe people find them useless precisely because they turn them off.
Re:Contracts for C++ (DbC) [pdf] by rramadass on Thursday November 14, 2024 @11:29AM (#42137833)
Finally, somebody said it! I am always bemused when people say they turn off contracts in production code. They don't understand the difference between contracts (a program state guarantee) and testing for special/error cases (must be handled explicitly). The excuse usually given is runtime performance which can be mitigated by using a subset from pre/post-conditions/invariants.
Re:Contracts for C++ (DbC) [pdf] by AlotOfReading on Thursday November 14, 2024 @09:01PM (#42143311)
C++ contracts as currently designed can execute 4+ times per call to do full checking. That gets expensive quickly.
Re:Contracts for C++ (DbC) [pdf] by rramadass on Friday November 15, 2024 @12:07AM (#42144104)
But they also give you 4 different evaluation semantics (ignore, observe, enforce, quick_enforce) to tweak as needed. You don't need to do full checking everywhere and always.
Re:Contracts for C++ (DbC) [pdf] by mempko on Monday November 18, 2024 @03:58PM (#42176949)
Exactly. What I do is litter my code with contracts. I then profile to find the hot loop and minimize (not turn them off) there. For the 99% of the other code, the user won't notice any slowdown.

The value is just too high to turn them off in production. Do you want bug free code? This is the only way I know how to do it.