Another idiom I wish were gone from phobos/druntime

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 4 17:18:08 PST 2015


On Thursday, 5 February 2015 at 01:07:56 UTC, Andrei Alexandrescu 
wrote:
> On 2/4/15 4:47 PM, deadalnix wrote:
>> 1/ the initial is overly long because the styling is wasteful.
>>
>> void foo() in {
>>   ...
>> } body {
>>   ...
>> }
>>
>> Is simply one line more than not using contracts.
>
> Would introduce an exception to our brace-on-its-line rule.
>
> I need to take issue with "that code is not using contracts". 
> Using assert _is_ using contracts.
>

My definition of an in contract is a condition that the caller is 
responsible to verify.  It appears that your definition is that 
it's a condition on a function argument (doesn't matter who is 
responsible).  I believe that Walter's definition of Contract 
programming is the definition I'm referring to.  I remember 
watching one of his talks on contract programming and the 
performance/optimization benefits he talked about would only 
apply if a contract made the callee responsible for the asserts.

The responsible party, caller/callee matters.  As far as I know, 
D is the first language to allow a function to make the caller 
responsible for verifying an assert.  Even before I saw this in 
D, I always wondered why no languages provided a way specify 
this. H.S. Teoh had a good response on why it matters to specify 
caller/callee so I'll refer to his response instead of re-hashing 
what he already said.


More information about the Digitalmars-d mailing list