DIP 1003: remove `body` as a keyword

Mark via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue Dec 13 14:27:09 PST 2016


On Thursday, 24 November 2016 at 14:06:40 UTC, Jonathan M Davis 
wrote:
> Personally, I don't care much about having body as a usable 
> symbol. It occasionally would be useful, but I can live without 
> it. However, I _do_ find it very annoying that it's required 
> for the function body when you have contracts. After all, it's 
> not required when you write the function normally. Why should 
> it be required when you have contracts on the function? The 
> braces after the contracts are clearly for the function body. 
> They couldn't be for anything else. The compiler always 
> requires that the body be last after the in and out contracts, 
> making the body keyword totally redundant. So, I've never 
> understood why the body keyword was required. As far as I can 
> tell, it fixes no ambiguity. It's just extra typing, and it 
> makes contracts that much more verbose, which makes me that 
> much more inclined to just not bother with them and put the 
> assertions in the function body - particularly when I'm already 
> of the opinion that they add no value outside of inheritance, 
> because assertions at the beginning of the function take care 
> of in contracts, and unit tests are really what covers the out 
> contract case anyway (particularly since it's very rare that 
> you can have a general test for the out contract rather than 
> testing that specific input results in specific output).
>
> - Jonathan M Davis

General tests of output are not so rare. The premise of 
property-based testing is being able to write such tests. Going 
over the functions in std.algorithm, for almost every one of them 
I can find a nontrivial property that any output should satisfy 
(for a valid input).


More information about the Digitalmars-d-announce mailing list