O'Reilly logo

Learning D by Michael Parker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Contract programming and unit tests

D has built-in support for contract programming and unit testing. D's contract programming implementation consists of two loosely related features: invariants and function contracts. None of these features would be as useful as they are without the assert expression.

Before we dig into the details, I'd like to point out that all of these features, except unit tests, are enabled by default. Passing -release to the compiler will disable asserts, function contracts, and invariants. Typically, you'll want to leave that flag out during development and use it when you are ready to start testing the release version.

Assert contracts

The assert expression evaluates a Boolean expression and throws an AssertError when the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required