On Saturday, 4 November 2017 at 16:57:50 UTC, Adam D. Ruppe wrote:
On Saturday, 4 November 2017 at 15:27:39 UTC, Ola Fosheim Grøstad wrote:
No, Jonathan is correct. The postcondition should be able to access values as they were stated in the precondition.

Yes, they should be able to access values, but D's limitations on this doesn't make them useless or replaced by unittests. They do a different job than unittests.

But then they do a job that subtyping does better…? So why do this with "contracts"?

Anyhow, I think the ideal for contracts in terms of debugging is to express postconditions in terms of public interface rather than internal representation, e.g. for a stack push:

oldthis.size() + 1 == newthis.size() // or length() or whatever the interface provides

Then hammer the interface in unit tests rather than writing the explicit test in the unit test itself. (e.g. the unit test does not have to know the conditions, just explore a wide range of configurations).


Reply via email to