Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Redundant testing by caller and by callee as a style of defensive programming is largely discredited within the C and C++ community, the main problem being performance. The usual discipline in C and C++ is to require validation only on one side of each interface.

When writing a library, each exposed function should perform a validity check on its parameters. Validity checks allow the library to survive at least some forms of improper usage, enabling an application using the library to likewise survive, and often simplifies the task of determining the condition that caused the invalid parameter.

...