9.9 Assertions*
One connotation of the term assertion suggests what it is about: assurances . Assertions formulate statements that must always be true if the code runs correctly. If a condition isn’t met, an exception will follow, indicating that something must have gone wrong in the program. The use of assertions in code promotes documentation for the valid program state.
You can distinguish between the following types of assertions:
-
Precondition : A state that must always be true prior to an operation
-
Postcondition : A state that must always be true after an operation
Formulating correct states is an essential element of design by contract , a development method that involves establishing a “contract” about what a program must ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access