Live data from Hacker News

Contracts for C++ (DbC) [pdf]

isocpp.org

31–40 of 48 posts

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

#31

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…

Yet companies like Eiffel Software, and Ada vendors with Ada/SPARK, are still in business with people paying for using their tools, in a day and age where many devs refuse to pay for their tooling.

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

#32
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.

Definitly, otherwise Eiffel Software would have closed shop by now.

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

#33
post #27

Anyone interested in other languages that implement this should take a look at the SPARK subset of Ada. Pre and postconditions work in the same way and enforce the same behaviour described here (or at least that's what I understand it to do from a quick skim through)

Wasn't Eiffel the first "design by contract" language? https://en.wikipedia.org/wiki/Eiffel_(programming_language)

Yes, with key books based on it.

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

#34

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…

SAL is wildly successful in the Windows world and is basically a contract language embedded in C macros.

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

#35

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…

I use them for all my code. They are far from useless. You never want to turn them off in production either since that's a source of important information. You are right programmers don't write them, but that says nothing about contracts and a lot about how programmers are trained.

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

#36

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…

A reference for your dissertation? The usefulness (or lack thereof) of contracts was famously discussed in 1997 in this paper: https://www.irisa.fr/pampa/EPEE/Ariane5.html (with additional comments here: https://www.irisa.fr/pampa/EPEE/Ariane5-comments.html ). I have tried several times (a couple of decades ago) to introduce DBC in Python, using one of the many available libraries (for an overview: see https://lab.ab…

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]

#37
post #36

Earlier quoted context omitted.

A reference for your dissertation? The usefulness (or lack thereof) of contracts was famously discussed in 1997 in this paper: https://www.irisa.fr/pampa/EPEE/Ariane5.html (with additional comments here: https://www.irisa.fr/pampa/EPEE/Ariane5-comments.html ). I have tried several times (a couple of decades ago) to introduce DBC in Python, using one of the many available libraries (for an overview: see https://lab.ab…

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.

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]

#38
post #31

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…

Yet companies like Eiffel Software, and Ada vendors with Ada/SPARK, are still in business with people paying for using their tools, in a day and age where many devs refuse to pay for their tooling.

Would be interesting if they pay because they want those tools or if they pay because they fear rewriting some old tools using those languages.

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

#39

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…

I worked in the telecom business 15 years ago on 4G (LTE) and there it was considered a big savior compared to how it was done before.

Basically before they had a lot of error handling code and it was a significant part of the code base (don’t remember but let’s say 50%) and this error handling code had the worst quality because it is very hard to inject faults everywhere. So basically the error handling code had a lot of bugs in it which made the system fail to recover properly.

But DbC was a godsend in the way that now you didn’t try to handle errors inside the program any longer. Now the only thing that mattered was that a service should be able to handle clients and other services failing. And failure in a few well defined interfaces is much easier to handle. So the quality became much better.

What about the crashes then? Well, by actually crashing and getting really good failure point detection it was much easier to find bugs and remove them. So the failures grew less and less. Also, at that time I believe there were 70 ms between voice packages so as long as the service could recover within that timeframe, no cell phone users would suffer.

Plus of course much less error prone error handling code to write.

And as someone else said, DbC should never be turned of in production. Of course, in embedded systems, speed is not so important as long as it is fast enough to not miss any deadlines. And you need to code it so it doesn’t miss deadlines during integration and verification with DbC so there is no reason to turn them off in production.

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

#40

Earlier quoted context omitted.

> 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

I'd assume the authors were aware of it, given that the original set of proposals from 2004-2006 directly compares facilities in D and Eiffel. Plus, you know, andrei. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n19...

I had missed this, the paper does mention D:

"Programming languages such as Eiffel and D have a Contracts facility; this paper proposes a Contracts facility for C++."

Post reply on HN