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

Chris Miller chris at dprogramming.com
Sun Jun 17 13:52:15 PDT 2007


On Sun, 17 Jun 2007 05:15:04 -0400, Russ  
<digitalmars.D.learn at russcon.removethispart.andthistoo.org> 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.  The postcondition contract often wants to talk  
> about how the resulting object is different from the original state of  
> the object.
> E.g. search for "old" on this page:
> http://archive.eiffel.com/doc/manuals/technology/contract/
>
> Here's a very simple example of what I want to do in D:
>
> void twiddleFoo(int direction, int amount)
> in
> {
>     assert(direction == UP || direction == DOWN);
> }
> out
> {
>     assert (direction == UP ? foo == old foo + amount : foo == old foo -  
> amount);
> }
>
> Is there away to achieve the effect of "old", i.e. for the "out" clause  
> to explicitly state that the value of "foo" has gone up or down by  
> "amount" according to the value of "direction"?  Am I not noticing  
> something in D?

Interesting. Perhaps amount.init could be used for the feature.


More information about the Digitalmars-d-learn mailing list