Once the programmer starts coding
he should use defensive programming.
This is similar to defensive driving
which means driving under worst-case scenarios
other drivers violating traffic laws, unexpected events or obstacles, etc
Similarly, defensive programming means developing code
such that it works correctly
under the worst-case scenarios from its environment.
For instance, when writing a function
one should assume worst-case inputs to that function,
i.e., inputs that are too large, too small
or inputs that violate some property, condition, or invariant
the code should deal with these cases
even if the programmer doesn't expect them to happen under normal circumstances.
note:
the goal is not to become an expert at fixing bugs
but rather to get better at writing robust (mostly) error-free programs in the first place.
As a matter of attitude
programmers should not feel proud when they fix bugs
but rather embarrassed that their code had bugs.
If there is a bug in the program, it is only because the programmer made mistakes.