Developers
Finding bugs in programs is not an easy task. There are no ready-made methods or recipes for success here. You can even say that this is art. However, there are general tips to help you with your search. This article describes the basic steps to take if your program does not work correctly.
Step 1: Report a bug to the tracker
After completing all of the steps below, it may happen that you are pulling your hair out of despair while still sitting at work when you realize that:
- You forgot some important detail about the error, for example, what it was.
- You could delegate it to someone more experienced.
You could delegate it to someone more experienced.
The tracker will help you not to lose the thread of thinking about the current problem and the one that you have temporarily postponed. And if you’re working in a team, it can help delegate the fix to a colleague and keep the entire discussion in one place.
You should write the following information to the tracker:
- What the user was doing.
- What he expected to see.
- What happened.
This should provide a clue on how to reproduce the error.
Step 2: search the net for the error message
If you have an error message, then you’re in luck. Either it will be informative enough for you to understand where and what the error is, or you will have a ready query for searching the web. Bad luck? Then go to the next step.
Step 3: Find the line showing the error
If an error causes the program to crash, try running it in the IDE under the debugger and see which line of code it stops at. The error doesn’t need to be on this line (see the next step), but at least it can give you information about the nature of the bug.
Step 4: Find the exact line where the error appeared
Once you find the line that shows the error, you can step back through the code to find where it is. Sometimes it can be the same line. But more often than not, you will find that the line on which the program fell has nothing to do with it, and the reason for the error is in the incorrect data that appeared earlier.
If you are tracking program execution in the debugger, you can walk back the stack trace to find the error. If you are inside a function called inside another function, then the stack trace will show the list of functions up to the very point of entry into the program (the main () function). If the error happened somewhere in the link library, assume that the error is still in your program – this happens much more often. Search the stack trace where the library function is called from in your code and keep looking.
Buffer overflow and array out of bounds
The number one problem in computer security. You are allocating less memory than the data you write there. Or you are trying to access an element outside the array.
Programmers can’t count
You are using the wrong formula. Make sure you don’t use integer division instead of taking the remainder, or you know how to convert a rational fraction to a decimal, etc.
String and number concatenation
You expect two strings to be concatenated, but one of the values ââis a number, and the compiler tries to do arithmetic. Try to explicitly cast each value to a string.