Program Correctness = program that does only what it is expected to do (no more or less). Reasoning for this is that a program cannot do everything
Programm correctness is defined by its roles and responsibilities. The concept is based on the metaphor in the business world that the client and the server need to agree on a contract of benefits and obligations.
Contracts are typically only checked in debug mode during software development. Later at release, the contract checks are disabled to maximize performance. Contracts can be implemented with asserts.
When defining a contract, a few things need to be defined:
preconditions = the routine's requirements -- what must be true for the function to be called, state of the world before the function is called, should not be used to make user input validation; if the requirements are not met, the function should not be called; it is the responsibility of the client to meet the requirements
- Acceptable and unacceptable input values or types, and their meanings
class invariants = a condition that is always true from the perspective of the caller and is not changed after the function exits, state;
postconditions = state of the world after the function is called
- Return values or types, and their meanings
Error and exception condition values or types that can occur, and their meanings
This approach assumes all client components that invoke an operation on a server component will meet the preconditions specified as required for that operation.
VS.
The function checks that preconditions and input values are respected. If the contract is not respected, then an exception must be raised early or the program terminates.
VS.
Because there is a layer that ensures preconditions are met between function invocation and function executions, input checking needs to be made by the caller to ensure the contract is respected and the function is executed.
When to use the client side focus
- I would see this applied only to internal services that are not exposed to the world. The services need to communicate with each other and there needs to be a level of trust and that not every request and every response are checked.