Another idiom I wish were gone from phobos/druntime

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 5 01:04:29 PST 2015


On 2/4/2015 5:32 PM, deadalnix wrote:
> On Thursday, 5 February 2015 at 01:07:56 UTC, Andrei Alexandrescu wrote:
>> Yah, I agree "in" is useful for overridable functions. In fact I'd say it's
>> useful _only_ for overridable functions.
>>
>
> Putting the contract in the caller is not only useful for overridable functions.
>
> 1/ If a lib is compiled in without contract, but your code is compiled with, you
> get the in contract to run when you call library code, but not the assert within
> the function.
>
> 2/ The optimizer see the properties of the argument when they get to the in
> contract. This information is lost in the callee, unless inlining goes on. that
> means the amount of contract the optimizer can remove statically is greater with
> in contract.

I was prepared to argue with you, but you're right on all points. Nicely done. 
Thanks!


More information about the Digitalmars-d mailing list