According to Chapter eight (“Defensive Programming”) of Code Complete, it talks how we can protect our program and how we can avoid error. It talks about the ways to make defensive program, such as Assertions, Exception, and Debugging. I think that the most important thing of Defensive programming is debugging because debugging is essential part of programming. I think that programming is rare to complete and run perfectly at once. It means that writing code perfectly is almost impossible. It usually has some errors because of lack of code. Of course, debugging is not only needed to complete writing code good to learn how we got wrong and to fix it. The reason why it is also good to learn is based on process of debugging.
What is process of it?
- Check the bug exists or not.
- Check where bug is in program.
- Check why error occurred.
- Make sure of way to fix it/ concern about correct way to run program.
- Fix and test it.
The purpose of this step to identify or find sigh of bug and knowing a situation that error occurred and knowing the way to avoid error.
2, Check where is bug in program:
In this step, we need to find and identify which program cause error.
3, Check why error occurred:
After we find a bug, we will need to know how error occurred. For example, the situation is program stops because of failure of data field. In this case, finding error of data field is purpose of this step.
4, Make sure of way to fix it/ concern about correct way to run program:
After we know the reason that program stops, we need to think about how to fix it. In this step, we need to know detailed information of what program is made for because some solution could change its purpose even if error is fixed.
5, Fix and test it:
After we find correct way to fix the bug, we need to test it and make sure that the way we try to fix deal with the bug or not and it cause undesirable side effect or not.
Thus, each step is important to complete code and fix program. In addition, those steps can tell us what, where, and how we got wrong. If we learn how we got wrong and fix it. We can avoid similar error next time.