Maybe D was wrong on contracts

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Sun Sep 13 18:32:43 UTC 2026


On Sunday, 13 September 2026 at 16:24:07 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> On 13/09/2026 5:54 PM, Walter Bright wrote:
>> On 8/17/2026 12:10 PM, Timon Gehr wrote:
>>> It's not like I didn't try: 
>>> https://issues.dlang.org/bugs/7584/
>> 
>> If anyone wants to fix D's contracts, feel free! It's worth 
>> doing.
>
> And I tried to solve the biggest problem with contracts... the 
> overuse of assert.
>
> Language needs an Exception analogus to assert, but that got 
> rejected.
>
> Until that is done, it will never have a chance to work 
> correctly.

Should be these 3:
IllegalArgumentException for in contract
IllegalStateException for invariant
IllegalResultException for out contract

for nothrow it should throw Error variants since they are 
uncatcheable.
for nogc plain assert and exit, or a global shared singleton 
immutable instance is thrown.

But seriously, if a contract fails it's not like end of the world 
in most cases, so it should be handled by exceptions so app can 
decide whether it is possible to handle it or not, where default 
is ofc exit fast from app.


More information about the Digitalmars-d mailing list