logoalt Hacker News

prydtyesterday at 6:16 PM1 replyview on HN

The contract programming in D is pretty much syntactic sugar for placing asserts at different parts of your program.

Refinement types can be used as compile time checks for preconditions and postconditions, while this contract programming is inserting runtime checks.

Here's a good post on the type state pattern in Rust (we don't actually have refinement types in something like Rust but the type state pattern is somewhere closer to refinement types on this spectrum): https://cliffle.com/blog/rust-typestate/


Replies

WalterBrightyesterday at 6:41 PM

In D, the covariance/contravariance of contract inheritance is an important aspect of the contracts.