On 3/16/2011 6:07 PM, Andrei Alexandrescu wrote:
On 03/16/2011 06:45 PM, bearophile wrote:
So a better solution is for the standard Phobos library to ship in two
versions, one compiled in release and not release mode, and DMD may choose the
right one according to the compilation switches. This removes most of the need
of enforce(). I suggest to deprecate enforce(). Until the problem with Phobos
compilation is solved and enforces are removed from Phobos, enforce() may
become a private Phobos function that user code can't import.

There may be some confusion somewhere. enforce is not supposed to be a sort of
assert. It is a different tool with a different charter. Use assert for 
assertions.

I want to emphasize Andrei's point.


1. Asserts and contracts are for detecting program BUGS. They are not for validating user input, checking for disk full, file not found errors, etc.

2. Enforce is for validating user input, checking for disk full, file not found errors, etc. Enforce is NOT for use in contracts or checking for program bugs.


Any use of enforce in Phobos that is checking for program bugs is itself a bug and should be entered into bugzilla for fixing.

Reply via email to