[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] hash.c change to use abort rather than assert
From: |
Bruno Haible |
Subject: |
Re: [Bug-gnulib] hash.c change to use abort rather than assert |
Date: |
Mon, 25 Nov 2002 20:34:56 +0100 (CET) |
Paul Eggert writes:
> In Bison we recently removed all uses of 'assert' in favor of 'abort'.
Just a stylistic preference: I prefer to turn
assert (bucket < table->bucket_limit);
into
if (!(bucket < table->bucket_limit))
abort ();
*not*
if (bucket >= table->bucket_limit)
abort ();
The reason is that it is generally helpful to thing in terms of
statements which are expected to be true. You can also call them
invariants. In other words, the code before the 'assert' should
_ensure_ that
bucket < table->bucket_limit
and the code following the 'assert' can _rely_ on
bucket < table->bucket_limit
It helps the thinking (for me at least) if this expression is also
found in the code or in a comment, and not its converse.
Bruno