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

Russ digitalmars.D.learn at russcon.removethispart.andthistoo.org
Sun Jun 17 02:15:04 PDT 2007


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?


More information about the Digitalmars-d-learn mailing list