D's design by contract is missing "old"?
Russ Williams
digitalmars.D.learn at russcon.removethispart.andthis.org
Mon Jun 18 09:11:50 PDT 2007
Manfred Nowak Wrote:
> Is Eiffel really capable of for example holding complete arbitrary
> "old" databases for each recursive call of a modifying function?
It always worked fine for me. The compiler is essentially just saving the programmer from the repetitive error-prone tedium of explicitly writing the boilerplate code like "oldFoo = foo" to store the value at the start of the function call.
If you are getting at the question of "What if foo is not a simple scalar value, but some complex linked structure which itself gets modified in the course of the function call?" then, yeah, it gets trickier. You need to talk about a clone of foo in the postcondition then.
This may shed further light:
http://www.faqs.org/faqs/eiffel-faq/
LOLD: What does the 'old' keyword mean?
"The value of an Old expression old e is [...] the result
that would have been produced by evaluation e just before
the call's execution began." (ETL2, p.125). This is
useful in postconditions.
When using the keyword with a reference, it is clear
from the definition that the value of "old a" will be
the object to which 'a' referred at the beginning of
the routine, and not the old value of the actual
object. Obtaining a copy of 'a', if that is the
required semantics, has to be done explicitly:
... old (clone (a)) ...
This makes senses because copy and identity are issues
with multiple solutions -- a shallow copy as done by
'clone' by default may not be enough for instance -- and
a compiler cannot be reasonably expected to guess correctly
which interpretation is appropriate for a given usage.
More information about the Digitalmars-d-learn
mailing list