"body" keyword is unnecessary

Tony tonytdominguez at aol.com
Sun Nov 19 11:54:04 UTC 2017


On Sunday, 19 November 2017 at 11:02:37 UTC, bauss wrote:
> On Sunday, 19 November 2017 at 08:13:32 UTC, Tony wrote:
>> On Sunday, 19 November 2017 at 08:05:38 UTC, Tony wrote:
>>>
>>>
>>> OK, but how would someone who is looking at:
>>>
>>> https://docarchives.dlang.io/v2.074.0/spec/contracts.html
>>>
>>
>> I wish this board had an edit function. That should be
>>
>> "OK, but how would someone who is looking at:
>>
>> https://dlang.org/spec/contracts.html
>
> They wouldn't need to know. Obviously they know its purpose and 
> how it works if they have it in their source code, if they 
> don't have it in their source code and they look at contracts, 
> then they will be fine either way

They won't be fine either way if they are using LDC or GDC right 
now or they are using a slightly older version of DMD and they 
want to try using contracts. They will look at the documentation 
and think that they need to write "do" and their version of the 
compiler will only accept "body", which won't be documented.

> as it's not a required keyword anymore and thus doesn't require 
> documentation, since you can achieve the same semantics without 
> using the keyword.
>
> The keyword is completely irrelevant unless you're maintaining 
> old source codes, in which case you should already be aware of 
> how it functions and if you aren't then a little research won't 
> hurt.

"do" doesn't appear to be optional and the compiler still talks 
about the deprecated "body", even if any mention of it has been 
removed from the documentation:

import std.stdio : writeln;

int MyFunction(int input)
in
{
    assert(input >= 0);
}
out (result)
{
    assert(result > 100);
}

{
    return input + 100;
}


void main()
{
    writeln("output: ",MyFunction(10));
}



dmd --version
DMD64 D Compiler v2.077.0
Copyright (c) 1999-2017 by Digital Mars written by Walter Bright

dmd test_contracts.d
test_contracts.d(13): Error: missing `body { ... }` after `in` or 
`out`





More information about the Digitalmars-d mailing list