4 ms·
Let me be the first to point out that the article introduces Contract Programming in its extreme form, without calling it by name. This is something that Dlang
by gitgood36 3y ago
Let me be the first to point out that the article introduces Contract Programming in its extreme form, without calling it by name.
This is something that Dlang supported as a compiler feature for ages now: the ability to make an assertion about the object's internal state and have the compiler validate it whenever it changes.
Having it supported by the compiler rather than kludging the same out of a type system neatly sidesteps the problems named, like the validity of one field depending on the value of another field: you'll just use an invariant on the level where it can be validated, rather than on the basic types, and you'll also be able to use plain assertions rather than type constraints.