Replies: 4 comments 4 replies
-
Hi,
Unfortunately, I'm too busy at the moment. I'll come back to the thread
with my thoughts after October 22nd.
|
Beta Was this translation helpful? Give feedback.
-
Hi, I'm a deal author and have a little bit of experience with DbC from both sides. There are my thoughts:
To summarize: don't worry about some corner cases when DbC maybe not sound. Sure, some bugs will slip through it. Still, you will catch most of the bugs, and this is bold. For example, deal has linter, test generation, formal verification, CrossHair integration (think as verifier-driven fuzzying), runtime checks. You write a few contracts and get all that stuff for free. Pretty cool, huh? |
Beta Was this translation helpful? Give feedback.
-
Hi @amacfie , Call to authorithy. Alexander Chichigin wrote:
This is a bit of a futile intro. I also worked and researched with Betrand Mayer (I was a teaching and research assistant with him at ETH Zurich), and I can tell you that it works. Perhaps the problem is with the expectations or a very fuzzy definition of what "works" (or "doesn't work", for that matter) means. I did see contracts work in education. We had all our introductions to programming and software engineering classes with Eiffel. At least I haven't observed any issues (either as a student and among my co-students or as a teaching assistant). I did see contracts work on larger code bases. We used contracts intensively at one of my previous employers (Parquery) for a code base of about 200-300K LOC. The code base grew ever since and they are still using it. You have to be careful which contracts are turned when (we distinguished levels: unit test, integration test, end-to-end test, production), but that requires only negligible attention in practice . We caught quite some difficult bugs with contracts. For example, related to time conversions, edge cases in computer vision (e.g., image boundaries), out-of-sync caches and object properties (e.g., dictionary lookup over a list which always need to be in sync etc.). Many tests did not have to be written, so it was also a nice plus for the code maintenance. Expectations. Alexander Chichigin wrote:
I think this is a matter of expectations. I presume that Alexander Chichigin aims at very high correctness standards of the code. In that case, and I second what @orsinium said, contracts and conventional programming languages are not the appropriate tool. On the other side, I do not see how he defines "simple" or why you shouldn't use contracts to cover the simple cases though you can not cover the "complex" ones. Contracts are such a low-hanging fruit that I hardly ever see substantial arguments against using them in the code. Most arguments cluster around people being not used to write them and/or being unwilling to put the minimal additional effort to formalize the contracts. While I can not share companies' code, I can point you at the corpus of Python programs @pschanely, @LaurenDebruyn and I wrote and annotated with contracts: https://github.com/mristin/python-by-contract-corpus Another good example that comes to my mind is a plug-in for Thonny I wrote: https://github.com/mristin/thonny-sealed. The development of that plug-in would have been much harder were it not for contracts. Yet another example, though not in Python, is front end development with React and Redux where invariants can be neatly verified between each state update. For the example of that technique, see a simple game I wrote for my kids: https://github.com/mristin/bukvarko/blob/master/src/stateInvariants.ts All these cases might indeed qualify as "simple". Judging by my personal experience, having contracts in place helped the development substantially, especially by catching some nasty bugs and being able to have deeper tests with much less explicit unit tests. |
Beta Was this translation helpful? Give feedback.
-
Hi, @amacfie ! I'm kinda flattered you've found my old answer on Quora and traced me back to Github. 😊 Though I'm a bit saddened that you took my words out of context and used them as a background to pretty much irrelevant question. So to the question:
No they don't. The Quora question was about Dijkstra, so let me use another one of his quotes: "Tests can only show the presence of bugs but never their absence." (The quote isn't precise but the meaning is preserved.) That's obviously true, BUT. As exactly bug finding tool tests in general and contracts as a particular type of tests are indispensable and pretty efficient. Especially when combined with automation techniques like automatic test data generation (Property-Based Testing), fuzzing, mutation and so on. And as far as I can see this project does exactly that: it provides a tool to find bugs using Contracts and Automation. So the bottom line is: my comments about contracts failing to provide absence-of-bugs guarantee are completely irrelevant for a project aimed at finding bugs. And as a form of testing and partial static verification tool I personally a fan of contracts. I honestly believe it's better to have contracts than not, and encourage everyone to use them for their code. As well as tests and documentation. 😉 I was pretty disappointed contracts didn't make it into C# specification and were abandoned by Microsoft, they had pretty impressive and sophisticated work in that area. Anyway, thanks for mentioning me in this project I'm pretty impressed by what the maintainers do here and will recommend it to my friends who are very into automated testing, contracts, PBT and fuzzing. 😃 |
Beta Was this translation helpful? Give feedback.
-
@gabriel-fallen on Quora says
I'm curious if @pschanely, @mristin or others can comment on whether these statements have practical implications for people who use contracts or people who develop tools for contracts.
Beta Was this translation helpful? Give feedback.
All reactions