Subject: Re: assert vs BUG [was: [PATCH v1 05/10] cat-file: use delta_base_cache entries directly]

From: Junio C Hamano <[email-masked]>
Date: Mon, 19 Aug 2024 08:50:41 -0700

Eric Wong <[email-masked]> writes:

> Eric Wong <[email-masked]> wrote:
>> Patrick Steinhardt <[email-masked]> wrote:
>> > We shouldn't use asserts, but rather use `BUG()` statements in our
>> > codebase. `assert()`s don't help users that run production builds.
>> 
>> OK.
>
> Thinking about this more, I still favor assert() in common code
> paths since it's only meant to be used during development and
> later removed or neutralized (via -DNDEBUG).

I have a mixed feeling.

I agree that assert() is only meant to be used during development,
but we only want code that is polished enough to be added to the
system, so there is no place for assert() in the code in 'master'.

The point of BUG() is that it is not easily "neutralized", so it can
help safeguarding the production code from harming the end-user data
due to doing nonsense things without noticing that the precondition
is not satisfied for it to perform correctly.  It makes sense to
have it in both during development and after deployment.