Another idiom I wish were gone from phobos/druntime

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Sun Feb 8 08:47:43 PST 2015


On Sunday, 8 February 2015 at 13:03:28 UTC, Marc Schütz wrote:
> On Thursday, 5 February 2015 at 16:34:38 UTC, Zach the Mystic 
> wrote:
>> Can you name one, or even imagine one? Bear in mind people 
>> like Andrei and myself do not like to read or write the later 
>> form and will use it much less, regardless of benefit.
>
> Daniel Murphy has (function stubs with `assert(0)`), here:
>
> http://forum.dlang.org/thread/maud7e$1j3u$1@digitalmars.com?page=7#post-mavf13:24130j:241:40digitalmars.com

assert(0) is a special case, and could be easily identified as 
such. My attitude would be to try to find a way to make this 
work, according to the principle that the common case should be 
easy, and the rarer case possible. The difference only applies to 
what the user is told about when the assert fails, and not the 
execution semantics themselves - so it's really not "screwing up 
the language", unless I'm wrong.

Also, in Daniel Murphy's example:

void func(int x)
in
{
    assert(x > 6); // If this assert fails the caller was incorrect
}
body
{
    assert(x > 7); // If this assert fails then 'func' has a bug.
}

I don't know how the second assert could men somethign different 
from the first. If you assert (anything but assert(0)) first 
thing, you certainly are not checking for bugs *within* the 
function - you're checking for entry conditions. So the question 
is whether the practical difference between the two asserts above 
is sufficient to prevent applying the syntax sugar. I personally 
can live with it either way (I can handle being told the the 
function failed when it was really the caller that failed), but 
it's a judgment call. I mean, this thread was literally called 
"Another idiom I wish were gone from phobos/druntime." I don't 
expect it is the last time someone will complain about it.


More information about the Digitalmars-d mailing list