Why no contracts for release build?

Andre via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 3 07:29:20 PDT 2014


Hi,
I currently think about whether or not contracts should be available
in release builds.

Assuming a small example, you have an account class with a deposit 
method, the input parameter must always be > 0.

void deposit(int amount)
in
{
   enforce(amount > 0);
}
body
{
   this.amount += amount;
}

If in release build the Contracts sections is removed, this means, I 
also need to add in addition in another place the enforce method. 
Otherwise in the productive scenario, this coding isn't secure anymore. 
This leads to code duplication.

I think Contracts are not a feature solely for unittests, they are a
fundamental part of classes/interfaces and theirfore should be available
in all builds.

What do you think?

Kind regards
André



More information about the Digitalmars-d mailing list