"Zach the Mystic" wrote in message
news:qxtyqdeewrjurmwhk...@forum.dlang.org...
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.
Here's one:
struct S
{
private:
static int instanceCount;
...
public:
void func(int x)
in
{
assert(x >= 0, "can't call func with negative x");
}
body
{
assert(instanceCount > 0);
}
}
The first assert checks something the caller has control over, the second
assert is a sanity check, and if it fails it's not an error in the caller.
Anyway, IMO there is zero chance of this making it into the language and
you're wasting your energy.