throws(statement, ErrorType)

bearophile bearophileHUGS at
Sun Jan 23 09:24:25 PST 2011

Jonathan M Davis:

>Not necessarily. In fact, in general, the tact that has been taken with Phobos is that you use assertions when you're verifying that Phobos is correct, and you use enforce (or an if-statement which throws an exception) when verifying that arguments given by outside code is correct.<

Phobos is using enforce mostly as a temporary work-around of the fact that the DMD compiler is not able to automatically switch using a debug version of Phobos or a release version of it when you compile your code in notrelase or relasee mode, so currently contract assertions are vanished unless you are using a template.

Maybe some enforce() will be left in Phobos, but currently they 1) slow down code, 2) kill inlining, 2) there's no way to disable them, 4) turn nothrow functions into throw ones even if there is no need for this in their algorithm, so most of those enforces() will need to be killed from Phobos.

>All that DbC says is that the arguments that a caller gives a function must meet certain requirements and that if they do, the result of the function will meet certain requirements. Verifying that the contract is kept has nothing to do with DbC. It's just good practice if you want to minimize bugs.<

I don't believe this :-)


More information about the Digitalmars-d-learn mailing list