The following puzzle is an excellent example of deductive reasoning:
Three geniuses stand in a single-file line, one behind the other. Each can see only to the front, so the rear person can see the middle and the front, the middle person can see the front, and the genius in the front cannot see anyone. You have five hats. Two are white, and three are red. You blindfold the three geniuses, who are utterly truthful, and put a hat at random on the head of each. Then you hide the other two hats and remove the blindfolds. You then ask each genius to name the color of his hat which he cannot see. The rear one says "I don't know." The middle on says, "I don't know." Then the front one says, "I know." What color is the front genius' hat?
Puzzle solving aside, what bearing does this have on programming? The ability to properly harness deductive reasoning in the development world is commonly overlooked. Some assume that all individuals naturally have this talent. Unfortunately, this is not true. Although each individual has some level of reasoning skills, deductive reasoning is based on fact. Basic reasoning skills commonly fall under inductive reasoning. Deductive reasoning is something that must be taught, experienced, and practiced. It is by far the best problem solving tool available to a developer.
For simplicity, let's dive into a non-programming example. A user reports a non-functional keyboard. The first step is to validate if the problem is the keyboard or computer. To validate this, obtain a known working keyboard from another computer and swap them (using the same ports). If the good keyboard works on the computer in question, then it had a bad keyboard, right? Not so fast. It's important not to make assumptions. Try the "suspected" keyboard on the known working computer. If it does not function, then the keyboard is bad. If it's functional, then the test is inconsistent and therefore invalid. Too many variables are in play. Seek to eliminate those variables and start over. The same rules apply if the problem was the computer and not the keyboard. That is basic deductive reasoning.
The following are a few tips about problem solving with deductive reasoning:
- While building a hypothesis, be sure to validate the factual nature of each element. The biggest pitfall of deductive reasoning is conclusions made on invalid data or facts.
- Validating a factual element may require prior knowledge or additional research. Do not make assumptions.
- Always compare expected outcomes against a "constant."
- Isolate testing to one change at a time. Multiple changes can invalidate results. If a test yields inconsistent results, unknown variables are in play. Seek them out.