Defensive programming is a style of programming designed to minimize the possibility of bugs introduced by code changes or unforeseen usage of the software.
Defensive programming is a style of programming designed to minimize the possibility of bugs introduced by code changes or unforeseen usage of the software. Examples of this style include "yoda" conditions where the constant is placed before the variable being tested if (42 == foo)
to cause compile time errors if the assignment equals was used rather than the comparison form. Another example is to always having braces around a block (e.g. single statement for loops) to reduce the possibility of a later code addition forgetting to add them and causing the statement to be in the wrong scope.