assume, assert, enforce, @safe

via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 3 02:13:30 PDT 2014


On Sunday, 3 August 2014 at 02:27:16 UTC, Jonathan M Davis wrote:
> On Saturday, 2 August 2014 at 09:46:57 UTC, Marc Schütz wrote:
>> On Friday, 1 August 2014 at 21:50:59 UTC, Jonathan M Davis 
>> wrote:
>>> And why is that a problem? By definition, if an assertion 
>>> fails, your code is in an invalid state,
>>
>> Only in an ideal world. In practice, the condition in the 
>> assertion could itself be incorrect. It could be a leftover 
>> after a refactoring, for instance.
>
> Then it's a bug, and bugs make programs do wrong and invalid 
> things. I certainly don't see any reason to not optimize based 
> on assertions just in case someone screwed up their assertion 
> any more than I see a reason to avoid optimizing based on 
> something that's wrong in normal code.

Yes, it's a bug. The purpose of asserts is to detect these kinds 
of bugs, not to make it harder to detect them, and their effects 
worse.


More information about the Digitalmars-d mailing list