I’ve never really programmed with a design by contract language and I certainly don’t want this post to become a war on dynamic vs static typed systems.
My question after reading a while is the one in the title: everything a type system can “catch”, can also a design by contract?
In some sites I’ve read things like “contracts are types on steroids”, and claims like that. But is it really a true superset?
Or put in other way, can a dynamic language with contracts have the same and more verification (again, at runtime) than a statically typed language without them?
Thanks!
No. Only local properties can be checked dynamically, whereas properties that require some kind of global knowledge cannot. Think of properties such as something being unique, something not being aliased, a computation being free of race conditions or dead locks. A suitable static type system can verify such properties, because it has the ability to establish certain invariants on the context of the expression that is being checked.