An important (if not the main) goal of statements is to document invariants that must be held at a certain point in the code. The fact that assert can also interrupt the program if the invariant is broken is just icing on the cake, albeit very useful. I would say that in a typical program, 90% of the statements are statements that obviously cannot fail and never fail. In other words, assert is pretty much a sort of formalized commentary language. Formalized in the sense that these "comments" are written in one language, the rest of the code is written in (C / C ++), and not plain English.
Your code example states that the pointer here should not be empty. That is why he is. In this sense, this assert not redundant.
As for the thread of execution, assert always redundant, so assertions are usually not compiled in the version version of the code. There is nothing to prevent you from storing statements in the release code, but this is usually done by introducing a special kind of “release statement”. In any case, if the core functionality of the code depends on the actions taken by the statement, it is not good programming practice. Statements should be redundant because the core functionality of the code.
source share