When an assert goes off what does it mean? In the codebases I work in, a failing assert doesn't always indicate that the code is about to fail.
There actually are several conditions that we want to check with asserts. The first three are from Meyer's Design By Contract:
I also see two other real-world uses of asserts:
The second set of uses are good, but can make code hard to change because making changes can set off a lot of asserts.
It is useful to distinguish between the cases above. Eiffel does the first three with REQUIRE, ENSURE and INVARIANT. Unfortunately, in plain C++ or C# we just have Assert() which doesn't give any context. We are moving to using different Assert-like macros in our codebase: