Improve "Improve Contract Syntax" DIP 1009

Mark smarksc at gmail.com
Sat Nov 4 18:15:24 UTC 2017


On Saturday, 4 November 2017 at 15:38:42 UTC, Jonathan M Davis 
wrote:
> On Saturday, November 04, 2017 15:27:39 Ola Fosheim Grøstad via 
> Digitalmars- d wrote:
>> On Saturday, 4 November 2017 at 14:12:08 UTC, Adam D. Ruppe 
>> wrote:
>> > On Saturday, 4 November 2017 at 13:59:39 UTC, Jonathan M 
>> > Davis
>> >
>> > wrote:
>> >> [...]
>> >
>> > I think that sqrt example is just bad. Out contracts 
>> > shouldn't be testing specific values, but rather ranges or 
>> > nullness or other such things that arguably should be part 
>> > of the return type, but just don't fit in the type system 
>> > for whatever reason.
>>
>> No, Jonathan is correct. The postcondition should be able to 
>> access values as they were stated in the precondition.
>
> In principle, that would be nice, but in practice, it's not 
> really feasible. In the general case, there's no way to save 
> the state of the parameter at the beginning of the function 
> call (you could with some types, but for many types, you 
> couldn't). IIRC, it's been discussed quite a bit in the past, 
> and there are just too many problems with it.
>
> - Jonathan M Davis

Yeah, I can see some of the problems that would arise from that. 
I think out contracts can work well for @safe strongly pure 
functions, but IIRC most functions in Phobos aren't strongly 
pure. Too bad. :(


More information about the Digitalmars-d mailing list