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? Enforce should not be used in contracts so the "Use assert in contracts" statement is correct and should remain. 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

Reply via email to