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

Moritz Maxeiner via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 23 06:58:38 PDT 2017


On Friday, 23 June 2017 at 13:26:53 UTC, jmh530 wrote:
> On Friday, 23 June 2017 at 13:00:30 UTC, Steven Schveighoffer 
> wrote:
>>
>> The out contract looks pretty good actually. The in contract, 
>> not as good. That looks like a comma expression. I'd rather 
>> see this be:
>>
>>      in(x > 0)
>>      in(y > 0)
>>
>> or
>>
>>      in(x > 0 && y > 0)
>>
>> In this case, we have something I think I would support.
>>
>> -Steve
>
> I agree.

Same here: Kudos (!) to Solomon for the out resembling foreach, 
but I don't support comma separation within in contracts, as it's 
inconsistent when compared to `&&` and `||`.
Adjusted earlier example:

---
int myFunc(Args...)(Args args)
   if (Args.length > 2)
   in (args[0] != 0, "Yikes!")
   in (args[1] > 1)
   out (result; result > 0, "Oops...")
   out (; globalStateStillValid) { ... }
---

Looks nice and clear to me.

OT: Anyone interested in a DIP for more template constraint 
unfulfilled information in a consistent way to contracts (?) :
---
int myFunc(Args...)(Args args)
   if (Args.length > 0, "Starving!")
   if (Args.length > 1, "Still hungry!")
   if (Args.length > 2, "Just a little bit more!")
   in (args[0] != 0, "Yikes!")
   in (args[1] > 1, "Why you do this?")
   out (result; result > 0, "Oops...") { ... }
---


More information about the Digitalmars-d mailing list