Boost logo

Boost :

From: Kevin Atkinson (kevinatk_at_[hidden])
Date: 2000-06-09 12:19:57


On Fri, 9 Jun 2000, Beman Dawes wrote:

> At 03:42 PM 6/9/00 +0200, Branko wrote:
>
> >Right. IMHO this could be another general Boost guideline: Always
> choose
> >safety over efficiency. When providing both, make the safer
> implementation
> >the default.
>
> Interesting suggestion!
>
> But I don't think it is quite that simple. There are a fair number
> of cases (portions of the STL for example) where efficiency wins.
>
> Like so many engineering decisions, it is really a cost versus
> benefits decision. We aren't, for example, willing to execute
> everything interpretively so more safety checks can be applied.
>
> Let's see if there is a safety versus efficiency guideline we can
> agree on. How about:
>
> "Choose safety over efficiency, particularly when the risk is great
> or the cost of safety is low. If separate safe or efficient
> variations are provided, the safer should be the default."

I think that safety should be the default when debugging a program, but
when compiling for production use efficiency should be the default
*unless* the cost of safety is cheap as for as efficiency goes. For
example when debugging bounds checking is a very good thing however when
creating the executable for production use bounds checking should be
turned off as it is rather costly as far as performance goes.

How about a debug_assert. That is an assert than can be turned off when
not debugging. I don't recommend using assert because I often use assert
for non-costly checks. Asserts are better than throwing exceptions for
debugging because they don't unwind the stack.

-- 
Kevin Atkinson
kevinatk_at_[hidden]
http://metalab.unc.edu/kevina/

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk