Last update July 28, 2009

Coming From /

(redirection from Notes For Programmers Used To / Eiffel)

No "old" operator for function postconditions

Unfortunately D lacks Eiffel's "old" or any equivalent mechanism for the postcondition ("out") statements to refer to the original value which "this" had at the start of the function call.

Full Design By Contract includes a way to compare the object's values at the start and end of the function invocation, which is often necessary in order to define what the function does to the object. ( gives further discussion of this element of DBC.)

Thus something like

void insertFoo(Foo f)
    assert(numberOfFoos == old(numberOfFoos) + 1);
is apparently not easily possible to represent in D without support from the language/compiler itself. (The notation old(numberOfFoos) would mean the value of numberOfFoos at entry to the function insertFoo, as the equivalent notation in Eiffel does.)


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: July 28, 2009 1:30 (diff))