Show HN: Design by Contract (tm) – C++
github.com
Show HN: Design by Contract (tm) – C++
1–7 of 7 posts
Re: Show HN: Design by Contract (tm) – C++
#2EDIT: Apparently it refers to the variable with the value at the entry point.
Re: Show HN: Design by Contract (tm) – C++
#3Re: Show HN: Design by Contract (tm) – C++
#4An exception, by definition, is to enable recovery from externally imposed events in a well-defined program state.
The only useful, meaningful response to discovering a contract violation is termination. Throwing an exception is the worst imaginable response.
Re: Show HN: Design by Contract (tm) – C++
#5Every pre-, post-, and invariant condition violation represents a programming error, at an indeterminate point in the past, rendering the state of the computation unknown, and likely undefined, and definitely unrecoverable. An exception, by definition, is to enable recovery from externally imposed events in a well-defined program state. The only useful, meaningful response to discovering a contract violation is termi…
Re: Show HN: Design by Contract (tm) – C++
#6I don't understand what 'OLD' does. EDIT: Apparently it refers to the variable with the value at the entry point.
This is because all of the virtual methods that have been overriden are visited in order to gather their assertions, but not execute their DO(). So while the assertions are being collected it also collects OLD() values which then can be tested at the called virtual method in its ENSURE() clause.
OLD is a complicated mechanism to implement in C++ because it requires saving current variables at the same time deferring the code to be executed.
Using the OLD() and ENSURE() (along with the other) clauses together, is described as subcontracting where subclasses "require less" and "ensure more", given in the https://en.wikipedia.org/wiki/Object-Oriented_Software_Const... (first edition).
Re: Show HN: Design by Contract (tm) – C++
#7Uh, run-time tests using C-style macros, much like assertions. Frankly, I would have been more impressed by some template/constexpr magic implementing compile-time tests.