Testing and Quality Assurance

How can I debug my code when I do not know what is wrong?

Debugging is a skill you can learn, and most professional programmers do it every day. The aim is to narrow down where the problem is, one step at a time.

A method to try: 1) Read the error message carefully. It often names the file and line number. 2) Reproduce the problem so you can make it happen every time. 3) Check what you expect against what actually happens, using print statements or a debugger to see the values of your variables. 4) Make the problem smaller. Comment out or remove parts of the code until the bug disappears, then add them back. 5) Change one thing at a time and test again. 6) Explain the problem out loud, step by step, even to a rubber duck. This often reveals the mistake.

If you are still stuck, search the exact error message or ask for help with a short example that shows the problem.

What is the most confusing bug you have had to fix?

Category