assert(0) behavior

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Wed Aug 5 03:31:29 PDT 2015


On 4 August 2015 at 00:54, Walter Bright via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On 8/3/2015 8:50 AM, Steven Schveighoffer wrote:
>
>> 1. They aren't removed, they are replaced with a nearly useless segfault.
>>
>
> Not useless at all:
>
> 1. The program does not continue running after it has failed. (Please,
> let's not restart that debate.
> 2. Running it under a debugger, the location of the fault will be
> identified.
>
>
> 2. If we are going to put something in there instead of "assert", why not
>> just
>> throw an error?
>>
>
> Because they are expensive.
>
> To keep asserts in all their glory in released code, do not use the
> -release switch.
>
>
I think as a guideline, there are really only be two places where using an
assert makes sense in druntime/phobos.

1. Internal modules, such as rt and core.internal.
2. Inside contracts (in, out, invariant) or unittests.


Everywhere else - *especially* if it's part of a public API like core.time
- you should throw an Exception or Error based on what you see fit.

Because of this view, I'm not really in agreement with the addition of a
core.abort module.

Regards
Iain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150805/22cf8f8f/attachment-0001.html>


More information about the Digitalmars-d mailing list