D's design by contract is missing "old"?

Russ Williams digitalmars.D.learn at russcon.removethispart.andthistoo.org
Sun Jun 17 08:37:20 PDT 2007


Serg Kovrov Wrote:

> > As far as I can tell, there is no "old" (as in Eiffel) for the function postconditions, which makes them a lot less useful.  "Old" is an essential part of DBC.
> 
> I have proposed some time ago that 'in' and 'out' could share same 
> scope. That way it would be easy to achieve this (and more). 
> Unfortunately, no one in NG were showing interest in it.

That would certainly be an improvement... but it still forces the programmer to explicitly declare and initialize the various "old" variables - very repetitive common boilerplate code that should be automatically handled by the compiler (e.g. as in Eiffel) instead of explicitly appearing in the source code.

http://digitalmars.com/d/cppdbc.html notes the drawbacks of making the programmer explicitly write a bunch of code for preconditions and postconditions in languages like C++ which don't have built-in support ... "By adding support for DbC into the language, D offers an easy way to use DbC and get it right."  The exact same argument holds for "old" in the postconditions, which very often need to refer to the starting value of "this" to be useful.


More information about the Digitalmars-d-learn mailing list