www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DIP 1009--Improve Contract Usability--Formal Review

reply Mike Parker <aldacron gmail.com> writes:
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
Aug 30
parent reply Mark <smarksc gmail.com> writes:
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; }
Aug 30
next sibling parent reply Moritz Maxeiner <moritz ucworks.org> writes:
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
Aug 30
parent Mark <smarksc gmail.com> writes:
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.
Aug 30
prev sibling parent MysticZach <reachzach ggmail.com> writes:
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."
Aug 30