Thread overview
DIP 1009--Improve Contract Usability--Formal Review
Aug 30, 2017
Mike Parker
Aug 30, 2017
Mark
Aug 30, 2017
Moritz Maxeiner
Aug 30, 2017
Mark
Aug 30, 2017
MysticZach
August 30, 2017
The first stage of the formal review for DIP 1009 [1], "Improve Contract Syntax", is now underway. From now until 11:59 PM ET on September 13 (3:59 AM GMT on September 14), the community has the opportunity to provide last-minute feedback. If you missed either of the two preliminary review rounds [2][3], this is your chance to provide input.

At the end of the feedback period, I will submit the DIP to Walter and Andrei for their final decision. Thanks in advance to those of you who participate.

[1] https://github.com/dlang/DIPs/blob/98052839441fdb8c6cc05afccb9a81d084051c4d/DIPs/DIP1009.md

[2] http://forum.dlang.org/post/gjtsfysvtyxcfcmuutez@forum.dlang.org

[3] http://forum.dlang.org/post/luhdbjnsmfomtgpydser@forum.dlang.org
August 30, 2017
On Wednesday, 30 August 2017 at 12:26:43 UTC, Mike Parker wrote:
> The first stage of the formal review for DIP 1009 [1], "Improve Contract Syntax", is now underway. From now until 11:59 PM ET on September 13 (3:59 AM GMT on September 14), the community has the opportunity to provide last-minute feedback. If you missed either of the two preliminary review rounds [2][3], this is your chance to provide input.
>
> At the end of the feedback period, I will submit the DIP to Walter and Andrei for their final decision. Thanks in advance to those of you who participate.
>
> [1] https://github.com/dlang/DIPs/blob/98052839441fdb8c6cc05afccb9a81d084051c4d/DIPs/DIP1009.md
>
> [2] http://forum.dlang.org/post/gjtsfysvtyxcfcmuutez@forum.dlang.org
>
> [3] http://forum.dlang.org/post/luhdbjnsmfomtgpydser@forum.dlang.org

I see that in the previous review rounds some people suggested various keywords for designating the return value of a function ("return", "result", ...) in an `out` contract. What about using a plain old underscore? For example:

int abs(int x)
out(_ >= 0)
{
    return x>0 ? x : -x;
}
August 30, 2017
On Wednesday, 30 August 2017 at 14:05:40 UTC, Mark wrote:
> [...]
>
> int abs(int x)
> out(_ >= 0)
> {
>     return x>0 ? x : -x;
> }

The ambiguity issue of having two results in one scope [1] applies.

[1] http://forum.dlang.org/post/oihbot$134s$1@digitalmars.com
August 30, 2017
On Wednesday, 30 August 2017 at 14:57:38 UTC, Moritz Maxeiner wrote:
> On Wednesday, 30 August 2017 at 14:05:40 UTC, Mark wrote:
>> [...]
>>
>> int abs(int x)
>> out(_ >= 0)
>> {
>>     return x>0 ? x : -x;
>> }
>
> The ambiguity issue of having two results in one scope [1] applies.
>
> [1] http://forum.dlang.org/post/oihbot$134s$1@digitalmars.com

Ah, I see the problem.
August 30, 2017
On Wednesday, 30 August 2017 at 14:05:40 UTC, Mark wrote:
> I see that in the previous review rounds some people suggested various keywords for designating the return value of a function ("return", "result", ...) in an `out` contract. What about using a plain old underscore? For example:
>
> int abs(int x)
> out(_ >= 0)
> {
>     return x>0 ? x : -x;
> }

I think it's good to be consistent with existing out contracts which require declaring the variable first. The identifier `__result` currently works, but the thing is, it takes fewer characters to write `out(r; r >= 0)` than to write `out(;__result >= 0)` (or `out(__result >= 0)`). The possibility of using a single character as the return identifier makes it hard, in my opinion, to justify complaints about the syntax being "too verbose."