Search code examples
c#code-contracts

One contract or several?


How many contracts?

Contract.Requires(name.NotEmpty() && identifier.NotEmpty());

or

Contract.Requires(name.NotEmpty());
Contract.Requires(identifier.NotEmpty());

Solution

  • I like the second one for a couple of reasons

    1. It scales to more contracts better
    2. Depending on your code contract library and the quality of messages it produces it may be easier to see exactly which condition failed