7.1. Diagnosing Errors

Before you can fix a mistake in your software, you need to determine that there is a mistake, then find the cause of the mistake. The last step is to figure out how to fix it. Diagnosis before cure.

A common mistake among beginners is to try to fix a mistake without fully understanding what is wrong. If you do not know what is wrong, you can only try random changes. Each random change almost inevitably makes the program worse, not better. As you make random changes, your program gets worse and worse until you need to throw it away and start over.

Before you try to fix anything, understand the cause. If you are too tired to do the diagnosis, put the program down and come back to it later.