← Back to context

Comment by WalterBright

4 days ago

I used to be a big fan of contracts, and even implemented it in the Zortech C++ compiler back in the 90's:

https://www.digitalmars.com/ctg/contract.html

I implemented it in D as well. But, it just turned out to not be very useful.

Can you go into why you didn't find them to be useful? Seems if done right they should allow many cases to warn/error at compile time while providing additional information to the optimizer in release builds. Technically with whole-program builds you could get the same with regular assertions in the function implementation but I can see how having them in the function prototype could make things easier in practice.

  • `assert` turned out to be much more useful.

    The only advantage contracts had was with inheritance hierarchies, and I don't use them enough to make it pay off.