assert vs BUG [was: [PATCH v1 05/10] cat-file: use delta_base_cache entries directly]
- From
- Eric Wong <e@80x24.org>
- Date
- Aug 18, 2024, 17:36 UTC
- Message-ID
- <20240818173637.M96307@dcvr>
- In-Reply-To
- <20240726074201.M876490@dcvr>
Eric Wong <e@80x24.org> wrote:
Show 5 quoted lines
> Patrick Steinhardt <ps@pks.im> 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).
IOW, I treat assert() as scaffolding that can/should later be removed once the code is proven to work well. We also have plenty of existing asserts in our codebase.
Furthermore, assert() is also a well known API which reduces the learning curve for drive-by hackers (I still consider myself a drive-by since my I do minimal C).