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

Russ Williams digitalmars.D.learn at russcon.removethispart.andthis.org
Mon Jun 18 14:25:24 PDT 2007


Manfred Nowak Wrote:
> I described how `old' might be implemented.
> 
> You described that not being forced to write explicit code only holds 
> in trivial cases.

Those trivial cases are very common, however.  In the nontrivial cases, the only explicit code would be needing to implement a clone or copy function for the type, which you quite often would already have anyway.  In all cases, you should never have to write additional declarations inside the function just to support expressing what you need in the postcondition.
 
> The non trivial cases need more work to be done. In terms of 
> information hiding a construct like `old( clone( a))' seems horrible.

Well, ANY mention of private members in the postcondition violates information hiding; such portions of a postcondition would just be sanity checking for the implementer of the function presumably and ideally not displayed by tools that generate a public interface for human readers.

But if there is a public function which returns some complex funky linked graph of objects, I don't see how "old(clone(funkyThing)) violates any kind of information hiding, given that funkyThing is publicly visible.

The problem has been solved and implemented in other languages, e.g. Eiffel, and Lava (a language about which I know practically nothing else, but just found while googling for more info about "old" :)
http://lavape.sourceforge.net/doc/html/DBC.htm


More information about the Digitalmars-d-learn mailing list