DIP 1009--Improve Contract Usability--Preliminary Review Round 1

Moritz Maxeiner via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 27 16:17:15 PDT 2017


On Tuesday, 27 June 2017 at 22:45:17 UTC, Mark wrote:
> On Tuesday, 20 June 2017 at 11:57:55 UTC, Mike Parker wrote:
>> DIP 1009 is titled "Improve Contract Usability".
>>
>> [...]
>
> Veering a bit off topic,the compiler doesn't treat contracts 
> any different from other code, does it? For instance, consider:
>
> [...]
>
> I would have liked to get a *compile-time* error [...]

Compile time contract violation checking?
While an interesting, I'm not sure the benefits would outweigh 
the implementation costs.

> If the contract system amounts to placing assertions at the 
> beginning and/or end of a function, it doesn't seem so useful 
> except for documentation and readability.

Considering that code is read a lot more than written those two 
are *critically* important.
What more do you expect? It could eventually be optimized to 
inject the in contract check at the caller's side (before 
entering the function), but the point of contracts is that they 
*aren't* violated. If they are, well, your program[1] is broken 
and needs to die.

[1] abstract: computational task; implementation barring safe 
thread/fiber killing: process


More information about the Digitalmars-d mailing list