Let's improve D's exceptions
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 18 07:18:46 PDT 2015
On 5/18/15 8:20 AM, Atila Neves wrote:
> One thing I like about `enforce` is that the program's run-time checks
> become positive instead of negative statements which I think is a lot
> more readable. i.e.
>
> enforce(foo && bar > 4, "...");
>
> instead of
>
> if(!foo || bar <=3) throw new Exception("...");
Yes, but that's a minor nuisance. I often do not rewrite conditions by
distributing the negation to avoid this problem. In that case, the
"operation" becomes basically:
if(!(...))
We could introduce a new 'when' keyword:
when(...)
joking, joking!!! don't start flaming :)
Alternatively, we could fix lazy parameters so they don't disable
inlining (though the weight carried by enforce is so minor, I still
don't think it's worth having).
-Steve
More information about the Digitalmars-d
mailing list