assume, assert, enforce, @safe

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 30 15:57:42 PDT 2014


On 7/30/14, 3:39 PM, Joseph Rushton Wakeling via Digitalmars-d wrote:
> On 31/07/14 00:01, Walter Bright via Digitalmars-d wrote:
>> 7. using enforce() to check for program bugs is utterly wrong.
>> enforce() is a
>> library creation, the core language does not recognize it.
>
> A question on that.
>
> There are various places in Phobos where enforce() statements are used
> to validate function input or class constructor parameters.

Yah, Phobos is a bit inconsistent about that. TDPL discusses the matter: 
if a library is deployed in separation from the program(s) it serves, it 
may as well handle arguments as "input". That's what e.g. the Windows 
API is doing - it consistently considers all function arguments 
"inputs", scrubs them, and returns error codes for all invalid inputs it 
detects. In contracts, the traditional libc/Unix interface does little 
checking, even a strlen(NULL) will segfault.

Phobos is somewhere in the middle - sometimes it verifies arguments with 
enforce(), some other times it just uses assert().


Andrei



More information about the Digitalmars-d mailing list