Contract Programming - D Programming Language

Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Calendar
  - Forums
  - IRC
  - Community Discord
  - Wiki
  - GitHub
  - Issues
  - Get involved
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

# Contract Programming

Contents

1. Assert Contract
2. Pre and Post Contracts
3. Invariants
4. References

Contracts enable specifying conditions that must hold true when the flow of runtime execution reaches the contract. If a contract is not true, then the program is assumed to have entered an undefined state.

Rationale:

Building contract support into the language provides:

1. a consistent look and feel for the contracts
2. tool support
3. the implementation can generate better code using information gathered from the contracts
4. easier management and enforcement of contracts
5. handling of contract inheritance

## Assert Contract

See AssertExpression.

## Pre and Post Contracts

See contracts.

## Invariants

See Struct Invariants and Class Invariants.

## References

- Contracts Reading List
- Adding Contracts to Java

Template Mixins
Conditional Compilation
Copyright © 1999-2022 by the D Language Foundation | Page generated by Ddoc on Thu Dec 15 17:30:33 2022