Saturday, November 25, 2017

Defensive Programming

Programming Defensively :

Consider designing your code to make bugs easier to track down. Bugs that raise an error far away from the root cause are harder to track down.

For example:

  • Declare the expected argument types of one or more of your functions.
  • You can either have the platform's evaluator perform the argument type checking or write your own code to check.
  • Include assertions in your code that check for a condition that holds if things are in working order.
  • Write a function to check that a condition holds and raise an error if the condition does not hold.


No comments: