Against if (!expression) throw new Exception(msg);
Don
nospam at nospam.com
Wed Mar 16 23:51:33 PDT 2011
Daniel Gibson wrote:
> I'd just like to summarize what useful stuff came out of this topic:
>
> * enforce is useful and more than a "always activated assert" ;-)
> * enforce prevents inlining and thus has negative impact on performance - this
> should probably be fixed.
> * enforce can't be used in weakly pure functions - this has the side-effect that
> iota() (maybe other functions as well) can't be used in pure functions - this
> should also be fixed. if fixing it is difficult /maybe/ if+throw should be used
> in potentially (weakly) pure functions in phobos until it is fixed
That was discussed on the Phobos ng some time back. I don't think it's a
compiler issue. It's just not pure because the lazy delegate isn't
marked as pure. Since you can overload on pure, I'm not sure why this
hasn't been done yet.
> * enforce's docs should probably mention null and false as well (even though
> maybe "zero" implies that, but it'd be clearer)
> - while I'm at it: I think the enforceEx signature in the docs is incomplete
>
> * it *may* encourage using the generic Exception instead of a specific more
> meaningful exception
> - related: some places in phobos could use a more specific Exception, e.g. iota()
>
> Cheers,
> - Daniel
More information about the Digitalmars-d
mailing list