|
Boost : |
From: William Kempf (sirwillard_at_[hidden])
Date: 2000-07-31 16:48:18
--- In boost_at_[hidden], "David Abrahams" <abrahams_at_m...> wrote:
>
> ----- Original Message -----
> From: "William Kempf" <sirwillard_at_m...>
> To: <boost_at_[hidden]>
> Sent: Monday, July 31, 2000 10:08 AM
> Subject: [boost] Re: compile time asserts [preconditions]
>
>
> > I strongly suggest you pick a different name. Preconditions
already
> > have a very well known meaning, for which a compile time assert
does
> > not work. Specifically, a precondition is one of the three
> > components that build up the foundation of DBC (design by
contract):
> > precondition, postcondition and invariant. All of these are
runtime
> > assertions. A precondition is that that must be upheld before a
> > function can be called (aka it's what you must insure when you
call a
> > function).
>
> They're not completely unrelated: the compile-time assert is a very
special
> case of precondition, where the precondition can be checked by the
compiler.
First, this is like saying that it's not unrelated to assert, which
is true, but obviously we won't call it assert. Second, it's not
really a precondition at all, compile time or otherwise. A
precondition is very specific in what it's asserting, or more
accurately, where it's asserting. A precondition is what needs to be
fullfilled before a function call can be made. These compile time
asserts are often used outside of this context.
> That said, I think the name "precondition" suffers the same problem
as many
> of the other names that we've seen: namely, that it looks like just
another
> way to write "assert". I am getting tired of listening to myself
nag y'all
> about this, but I insist that the name needs to contain some
indication that
> there is static checking going on:
>
> BOOST_COMPILER_ASSERT
> BOOST_STATIC_PRECONDITION
> BOOST_STATIC_ASSERT
> BOOST_STATIC_CHECK
>
> all work, with BOOST_STATIC_ASSERT being my favorite so far.
I agree with this totally. The word "static" is overused, but most
of us can easily understand its meaning in this context. It's
simpler (shorter) than BOOST_COMPILE_TIME_ASSERT, and though I
usually don't recommend a name based on it's brevity, in this case I
like the fact that it's shorter. I don't like the BOOST prefix, but
understand the necessity for this little evil.
As for the other suggestions:
BOOST_COMPILER_ASSERT - I don't think conveys the fact that this is a
compile time assert.
BOOST_STATIC_PRECONDITION - Still has the same problems as
precondition, IMHO.
BOOST_STATIC_CHECK - Is OK, but doesn't convey to me what the action
will be. The assert version does, since it shares a name with the
assert macro.
William E. Kempf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk