why no "old" operator in function postconditions, as in Eiffel?

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Wed Jun 20 06:22:54 PDT 2007


davidl wrote:

> That feature doesn't worth a keyword at all, and old(blah) pollutes the
> naming space. You have several choices already:
> 
> The following shows how your old keyword should work(NOTICE: the code
> would probably be not compatible with D2.0):
> 
> int func(int n)
> out(result)
> {
> static int[int] funcmap;      // create a func mapping here for further old
> keyword test
> // while this kind of sanity test would bloat the AA funcmap greatly
> // But I don't see any other solution without increasing runtime to
> solve this
> // problem in *any* other language
> funcmap[n]=result;
> if ((n-1) in funcmap)         // test if that has been calculated
> assert(funcmap[n]==funcmap[n-1]+1);
> }
> body
> {
> if (n<1) return 0;
> return func(n-1)+1;
> }
> void main()
> {
> func(3);
> }
> 

What is this supposed to solve? DbC is supposed to save the high level
representation of contracts. Also inheritance as implemented currently
breaks your example and your function is stateless, so there's absolutely
no need for 'old' in that.

>> Being a newbie, I already asked in the digitalmars.D.learn ... no one
>> there knew of a way to do this directly, only with various additional
>> explicit boilerplate coding by the programmer.

You can always extend the language with metaprogramming. ;)

>> Are there plans to add such support to D?  Searching the archives for
>> "old" and "Eiffel" and find virtually no mention of this, which amazes
>> me.  I found "old" to be extremely useful when I coded in Eiffel.  Not
>> having it in a language that bills itself as supporting DbC seems like
>> languages which only have "assert" and claim to be supporting DbC.

I hope so. DbC in most languages is a bad joke. They teach you to use @pre
and @post in javadoc comments in uni these days, but seriously nobody is
going to use it (correctly) if the compiler cannot enforce anything. That's
the whole point.



More information about the Digitalmars-d mailing list