3 ms·
I tried to find you a decent intro to the best approach at this, Design-by-Contract. The Eiffel site has a nice, short intro with examples and benefits: https:
by nickpsecurity 10y ago
I tried to find you a decent intro to the best approach at this, Design-by-Contract. The Eiffel site has a nice, short intro with examples and benefits:
https://www.eiffel.com/values/design-by-contract/introduction/ https://www.eiffel.com/values/design-by-contract/introductio...
It has been implemented in Java with the stuff inside JavaDocs. I know JML/Krakatoa integrated it with provers. Simplest is using it for interface checks, though, of expectations of what component is doing vs what it's actually doing. The DbC style lets you document your assumptions, have formal properties to derive tests from, work right there with the code itself, and even automatically generate tests in some tools. That last one is huge benefit as you know the tests will always be relevant to the module and don't have to maintain them. You can do your own tests at the system-level on stuff the module-level contracts might not capture.
I'm not sure I can help you for most of the others. Remember, though, you can implement the DbC assertions in code that's in the modules themselves called before and after they run. These can be set to turn off with a flag during production compiles. You can also write generators that pull them out of comments in your source files then produce a version of your program with the checks in them as tests. I can't find my original articles post-PC crash but the one below builds in Ruby a generator for C language DbC:
http://www.onlamp.com/pub/a/onlamp/2004/10/28/design_by_contract_in_c.html http://www.onlamp.com/pub/a/onlamp/2004/10/28/design_by_cont...
EDIT: Two for Python on StackOverflow that are kludgey but seem to help.
https://stackoverflow.com/questions/8563464/using-design-by-contract-in-python https://stackoverflow.com/questions/8563464/using-design-by-...