Preconditions and Postconditions

  1. One good way to write the comments of a function prototype is to break the comments down into two kinds of information called a precondition and a postcondition.

  2. The precondition states what is assumed to be true when the function is called. The function should not be used if the preconditions do not hold.

  3. The postcondition describes what will be true after the function is executed in a situation in which the precondition holds.

  4. For a function that returns a value, the postcondition describes the value returned by the function.

  5. For a function that changes the value of some argument variables, the postcondition describes all the changes made to the values of these arguments.

  6. From the function prototype and the preconditions and postconditions, one should be able to correctly use the function without knowing the definition of the function.