Live data from Hacker News

Contracts for C++ (DbC) [pdf]

isocpp.org

11–20 of 48 posts

Re: Contracts for C++ (DbC) [pdf]

#11

I did my dissertation work on software contracts. They are generally useless: programmers won't write them, or will write them incorrectly. Moreover, the runtime enforcement dominates all but the most-expensive functions, and contracts become an antipattern for helper functions due to their enforcement cost. Without intense compiler support and contract erasure such as David Van Horne's work, this is a dead idea that…

Interesting. I am a fan of DbC (following Meyer's Applying "Design by Contract" - pdf at https://se.inf.ethz.ch/~meyer/publications/computer/contract...) though due to runtime costs (as you point out) i limit it to pre-conditions only everywhere (almost all "policy" part of the code and less on the "mechanism" side) and tighter pre/post-conditions on module boundaries only.

> programmers won't write them, or will write them incorrectly.

I think this is a matter of education and discipline and not an argument for not using DbC.

If it is okay with you could you share your dissertation and maybe highlight the key points which led you to your conclusion of "They are generally useless"? I think it would be useful to know.

Re: Contracts for C++ (DbC) [pdf]

#12

Contract programming for C++ was implemented back in the 90's. https://www.digitalmars.com/ctg/contract.html It also appears in the D programming language: https://dlang.org/spec/contracts.html

"Contract programming for C++ was implemented back in the 90's."

-> Did the proposal authors contact you or refer to your work (or any other previous work)? It not, that would be a shame.

"It also appears in the D programming language"

-> Do people use it?

Re: Contracts for C++ (DbC) [pdf]

#13

More recent revision: https://isocpp.org/files/papers/P2900R10.pdf . It seems like they've added a few things since this draft. It's somewhat funny to hear "minimum viable product" in the context of a language standard/specification. I'd never thought of adding a feature to a language in that way before. The idea of design by contract (DbC) in C++ appears to have been around for a while too. The authors link to a "fo…

Languages are software products as well.

Many features in Java, C#, C++ have evolved as MVP across several language revisions before.

Lambdas, type inference, modules, unsafe code, constexpr,...

Re: Contracts for C++ (DbC) [pdf]

#14

Contract programming for C++ was implemented back in the 90's. https://www.digitalmars.com/ctg/contract.html It also appears in the D programming language: https://dlang.org/spec/contracts.html

"Contract programming for C++ was implemented back in the 90's." -> Did the proposal authors contact you or refer to your work (or any other previous work)? It not, that would be a shame. "It also appears in the D programming language" -> Do people use it?

> Did the proposal authors contact you

No

> or refer to your work (or any other previous work)?

No

I presume they simply didn't know about it. I emailed the authors.

> Do people use it?

Yes

Re: Contracts for C++ (DbC) [pdf]

#15

I did my dissertation work on software contracts. They are generally useless: programmers won't write them, or will write them incorrectly. Moreover, the runtime enforcement dominates all but the most-expensive functions, and contracts become an antipattern for helper functions due to their enforcement cost. Without intense compiler support and contract erasure such as David Van Horne's work, this is a dead idea that…

Is anyone using Eiffel language in the real world? The community seems so tiny, barely existing.

Re: Contracts for C++ (DbC) [pdf]

#16

Earlier quoted context omitted.

"Contract programming for C++ was implemented back in the 90's." -> Did the proposal authors contact you or refer to your work (or any other previous work)? It not, that would be a shame. "It also appears in the D programming language" -> Do people use it?

> Did the proposal authors contact you No > or refer to your work (or any other previous work)? No I presume they simply didn't know about it. I emailed the authors. > Do people use it? Yes

> Yes

The tiny subset of D userbase, which is tiny in its own.

Re: Contracts for C++ (DbC) [pdf]

#17
Assuming that this or something substantially identical does land for C++ 26 I think we should start betting on when SG23 (the committee's Study Group for "Safety and Security") is replaced by some hypothetical SG24 "Safety and Security No But Really".

We already know that because C++ Undefined Behaviour can cause what are called "Time Travel" defects and this paper doesn't do anything to prevent it, adding contracts in C++ can make your software less safe and induce more surprise behaviour. We also already know that C++ programmers tend to write erroneous UB tests when trying to grapple with edge cases that might induce Undefined Behaviour, setting off the very calamity they fear. So this new feature, rather than being (as its proponents claim) a way to improve the safety of C++ software, or neutrally becoming a dead letter as the UB "passes" contracts that in fact are not met, might instead become another footgun for the language.

A functioning SG23 should have caused this proposal to stall out until it can explain how it will prevent this problem, rather than merely re-stating the problem (in 3.6.4) and saying well that's unfortunate but maybe somebody else will fix it. That stance might be extremely unpopular with some C++ programmers, who believe they don't make mistakes, but as it stands this work will instead cause all the people who do make mistakes (which is in practice everybody) to regret using contracts. If SG23 isn't interested in preventing C++ from becoming even more unsafe, what's the point in the group existing?

Re: Contracts for C++ (DbC) [pdf]

#18
post #15

I did my dissertation work on software contracts. They are generally useless: programmers won't write them, or will write them incorrectly. Moreover, the runtime enforcement dominates all but the most-expensive functions, and contracts become an antipattern for helper functions due to their enforcement cost. Without intense compiler support and contract erasure such as David Van Horne's work, this is a dead idea that…

Is anyone using Eiffel language in the real world? The community seems so tiny, barely existing.

That doesn't matter when it comes to concepts/ideas which are useful overall. In this context DbC is a general idea/technique (derived from the Floyd/Hoare/Dijkstra school of "Program Correctness") useful for "large scale" Software Engineering.

Re: Contracts for C++ (DbC) [pdf]

#19

Assuming that this or something substantially identical does land for C++ 26 I think we should start betting on when SG23 (the committee's Study Group for "Safety and Security") is replaced by some hypothetical SG24 "Safety and Security No But Really". We already know that because C++ Undefined Behaviour can cause what are called "Time Travel" defects and this paper doesn't do anything to prevent it, adding contracts…

Aha, this for some reason links an ancient version of the proposal and current versions do forbid time travel across the contract, so, the result is not strictly worse which is an important improvement, no sure whether SG23 was involved in that outcome but it's a good idea either way.

Re: Contracts for C++ (DbC) [pdf]

#20

More recent revision: https://isocpp.org/files/papers/P2900R10.pdf . It seems like they've added a few things since this draft. It's somewhat funny to hear "minimum viable product" in the context of a language standard/specification. I'd never thought of adding a feature to a language in that way before. The idea of design by contract (DbC) in C++ appears to have been around for a while too. The authors link to a "fo…

This is the MVP, as the subset of the all the various contract proposals that stands a chance to pass approval, as the feature has been extremely contentious with irreconcilable positions on some details.
Post reply on HN