assume, assert, enforce, @safe

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 1 23:01:29 PDT 2014


On 8/1/2014 5:57 PM, Dicebot wrote:
> `enforce` does have overload which allows to use pre-allocated exception
> instance. Or, alternatively, we may need a similar helper wich does `if
> (!condition) abort()` with no interaction with -release or optimizer.

It still throws a *recoverable* exception, which requires the call stack to be 
populated with exception handling frames. Worse, it implies that program bugs 
are recoverable errors, when they are not.


> 1) one can always `enforce` with a pre-allocated Error, will druntime handle
> that as expected?

I don't know, but I don't see why not.


> 2) There is certain class of applications where even programming bugs can (and
> must be) considered recoverable. Network services that don't yet have full scale
> high availability infrastructure (and thus can't afford downtime of restarting
> the app) are quite likely to only terminate connection fibers when programming
> bug is found - it does not affect serving any other connections. It may be
> fundamentally wrong but is is pragmatical working approach.
>
> These questions are not theoretical - we regularly have discussion about how
> contracts may / should be used at work with no clear understanding / agreement
> so far. I am interested in simple set of guidelines that won't turn writing
> every single function in a guessing game (does a contract fit here?)

Putting it another way, consider the rules:

1. A newbie follows the rules because he's told to
2. A master follows the rules because he knows why the rules are good
3. A guru breaks the rules because he knows when the rules don't apply

As to the substance of your question, I can't do it proper justice in a few 
lines. It's an important issue, and it is worthwhile to thoroughly understand 
it, especially for the kind of programming you do and the leading role you have 
in it.

For that I recommend "Object Oriented Software Construction" by Meyers.

http://www.amazon.com/Object-Oriented-Software-Construction-Book-CD-ROM/dp/0136291554/

Don't let the OOP title throw you off. It is a very thorough treatment of 
contract programming, and the rules and their rationales, but in a readable 
manner. You won't be sorry you read it. It's only $34 used, a bargain.


More information about the Digitalmars-d mailing list