Debugging: Difference between revisions
No edit summary |
Mr. MacKenty (talk | contribs) No edit summary |
||
(29 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
== Terminology == | == Terminology == | ||
Line 9: | Line 6: | ||
== A debugging process == | == A debugging process == | ||
[[File:Arrows.png|right|frame|This is an important process for you to understand <ref>http://www.flaticon.com/</ref>]] | |||
6 Steps to fix an error | |||
The correct approach to debug is to follow a very structured procedure based on repeating the same steps for every bug, the reason for this is that bugs usually are symptoms of a much bigger problem going on, so in order for us to uncover the real nature of the error we have to make sure we do an exhaustive and systematic revision of it. | The correct approach to debug is to follow a very structured procedure based on repeating the same steps for every bug, the reason for this is that bugs usually are symptoms of a much bigger problem going on, so in order for us to uncover the real nature of the error we have to make sure we do an exhaustive and systematic revision of it. | ||
Line 35: | Line 32: | ||
# Logging. It can be to the console, file… It should help you to trace the error in the code. | # Logging. It can be to the console, file… It should help you to trace the error in the code. | ||
# Removing code. | # Removing code. | ||
<blockquote style="padding: 5px; background-color: #FAAFBA; border: solid thin gray;"> | |||
[[File:Exclamation.png]] This is one of the most important strategies you can use to find errors: | |||
''Take out half of the code from the action causing the program to produce an error and keep splitting the code until you find the error.'' | |||
</blockquote> | |||
=== Step 3. Analyze the error === | === Step 3. Analyze the error === | ||
Line 43: | Line 43: | ||
This is a critical step, use a bottom-up approach from the place the error was found and analyze the code so you can see the big picture of the error, analyzing a bug has two main goals: to check that around that error there aren’t any other errors to be found (the iceberg metaphor), and to make sure what are the risks of entering any collateral damage in the fix. | This is a critical step, use a bottom-up approach from the place the error was found and analyze the code so you can see the big picture of the error, analyzing a bug has two main goals: to check that around that error there aren’t any other errors to be found (the iceberg metaphor), and to make sure what are the risks of entering any collateral damage in the fix. | ||
=== Step | === Step 4. Fix the error. === | ||
That’s it, finally you can fix the error! | That’s it, finally you can fix the error! | ||
=== Step | === Step 5. Validate the solution.=== | ||
Run the program again and reproduce the same steps that you discovered in step 1. | Run the program again and reproduce the same steps that you discovered in step 1. | ||
<ref>http://www.makinggoodsoftware.com/2009/06/14/7-steps-to-fix-an-error/</ref> | <ref>http://www.makinggoodsoftware.com/2009/06/14/7-steps-to-fix-an-error/</ref> | ||
== See Also == | |||
[[Understanding error messages in Python]] | |||
== | |||
== References == | == References == | ||
Line 96: | Line 61: | ||
<references /> | <references /> | ||
[[Category:debugging]] | |||
[[Category: | |||
Latest revision as of 08:37, 8 December 2021
Terminology[edit]
In computers, debugging is the process of locating and fixing or bypassing bugs (errors) in computer program code or the engineering of a hardware device. To debug a program or hardware device is to start with a problem, isolate the source of the problem, and then fix it. A user of a program that does not know how to fix the problem may learn enough about the problem to be able to avoid it until it is permanently fixed. When someone says they've debugged a program or "worked the bugs out" of a program, they imply that they fixed it so that the bugs no longer exist.[1]
Debugging is the process of finding and resolving of defects that prevent correct operation of computer software or a system. Debugging tends to be harder when various subsystems are tightly coupled, as changes in one may cause bugs to emerge in another.[2]
A debugging process[edit]
6 Steps to fix an error
The correct approach to debug is to follow a very structured procedure based on repeating the same steps for every bug, the reason for this is that bugs usually are symptoms of a much bigger problem going on, so in order for us to uncover the real nature of the error we have to make sure we do an exhaustive and systematic revision of it.
The degree of formality when following the steps may vary depending on the bug, for critical errors it is better to document every single step in a document. For minor errors, or bugs found while coding it is just enough to follow them as a mental guideline.
Step 1. Identify the error.[edit]
This is an obvious step but a tricky one, sometimes a bad identification of an error can cause lots of wasted developing time.
A few tips to make sure you identify the bug correctly:
- See the error.
- Reproduce the error.
You never should say that an error has been fixed if you were not able to reproduce it.
- Understand what the expected behavior should be.
- Validate the identification.
Ask yourself: is this expected behavior or an actual error?
Step 2. Find the error.[edit]
Once we have an error correctly identified, it is time to go through the code to find the exact spot where the error is located, at this stage we are not interested in understanding the big picture for the error, we are just focused on finding it. A few techniques that may help to find an error are:
- Logging. It can be to the console, file… It should help you to trace the error in the code.
- Removing code.
This is one of the most important strategies you can use to find errors:
Take out half of the code from the action causing the program to produce an error and keep splitting the code until you find the error.
Step 3. Analyze the error[edit]
This is a critical step, use a bottom-up approach from the place the error was found and analyze the code so you can see the big picture of the error, analyzing a bug has two main goals: to check that around that error there aren’t any other errors to be found (the iceberg metaphor), and to make sure what are the risks of entering any collateral damage in the fix.
Step 4. Fix the error.[edit]
That’s it, finally you can fix the error!
Step 5. Validate the solution.[edit]
Run the program again and reproduce the same steps that you discovered in step 1.
See Also[edit]
Understanding error messages in Python