Spaghetti Code

Defensive Programming


Defensive Programming Shield

Defensive Programming

Defensive programming provides a form of design intended to ensure the continuing function of a piece of software under unforseen circumstances. These techniquies are traditionally employed when a piece of software could be misused.
However, overly defensive programming may safeguard against errors that will never be encountered and could incur runtime and maintenance costs. The possibility also exist that the code prevents too many exceptions and thus outputs unnoticed, incorrect results.
Defensive Programming ExampleIn the above example, the programmer decided that they would use the original instance of the "old_code" method rather than trust that the user's "new_code" method operates the same.