On 01/27/2018 04:59 PM, lobo wrote:
> On Saturday, 27 January 2018 at 22:53:37 UTC, Ali Çehreli wrote:
>> On 01/27/2018 10:33 AM, kdevel wrote:
>>
>>> I suggest the deletion of the sentence "Use assert in contracts."
>>
>> Done.
>>
>> Ali
>
> Wait, no this isn't right, is it?

It is right because that statement made one person to replace 'enforce's with 'asserts's.

> Enforce should not be used in
> contracts so the "Use assert in contracts" statement is correct and
> should remain.

I don't think enforce documentation is the right place to get into such matters. Warning against a potential misuse is fine but hinting at "correct use of assert vs. enforce" is not only distracting but also misguiding.

> I think the issue here is the OP is getting confused
> between assert vs. exception.
>
> Contracts (in D) are used to define and assert the agreed logic
> behaviour of the program code.
>
> Asserts catch logic bugs in the code that may lead to incorrect
> behaviour at runtime. Exceptions are for exceptional cases that crop up
> at runtime due to factors external to the code logic, e.g. invalid
> external state such as failing to open a file or a sensor not going off
> when it should because it is faulty.
>
> Asserts can be removed in -release code because it is assumed the logic
> has been asserted correct during debug builds and testing. The same
> reason compilers now are starting to optimise out code based on assert
> conditions.
>
> bye,
> lobo

All true.

Ali

Reply via email to