Stroustrup objects to adding Contracts to C++
Meta
jared771 at gmail.com
Mon Nov 9 18:40:01 UTC 2026
On Monday, 9 November 2026 at 12:19:30 UTC, Paul Backus wrote:
> On Monday, 9 November 2026 at 00:40:29 UTC, Walter Bright wrote:
>> https://www.stroustrup.com/Contracts_fundamental_flaws.pdf
>>
>> An interesting read, relevant to resurging interest in
>> improving D's contracts.
>
> Honestly, contracts in D are kind of a flop. Not because
> there's anything wrong with them in principle, but because the
> goals you'd use them to achieve are usually achieved more
> effectively by other means (unit testing, encoding invariants
> in the type system).
I don't agree. I think they're extremely useful for enforcing
runtime invariants that are very difficult or impossible to
express in the type system. You can use unit tests to achieve
something similar, but its clumsy and they're not really suited
for what contracts do.
> Meanwhile, they add a significant amount of complexity to both
> the spec and implementation, and have tricky edge cases around
> inheritance and separate compilation.
The inheritance issues are fixable. Separate compilation *is*
tricky... but that's not unique to contracts.
More information about the Digitalmars-d
mailing list