testing and debugging thereforea program can provide undetected fallacious answer for long periods of time such programs canand havecaused lot of damage program that evaluates the risk of mortgage bond portfolio and confidently spits out the wrong answer can get bank (and perhaps all of societyinto lot of trouble radiation therapy machine that delivers little more or little less radiation than intended can be the difference between life and death for person with cancer program that makes covert error only occasionally may or may not wreak less havoc than one that always commits such an error bugs that are both covert and intermittent are almost always the hardest to find and fix learning to debug debugging is learned skill nobody does it well instinctively the good news is that it' not hard to learnand it is transferable skill the same skills used to debug software can be used to find out what is wrong with other complex systemse laboratory experiments or sick humans for at least four decades people have been building tools called debuggersand there are debugging tools built into idle these are supposed to help people find bugs in their programs they can helpbut only little what' much more important is how you approach the problem many experienced programmers don' even bother with debugging tools most programmers say that the most important debugging tool is the print statement debugging starts when testing has demonstrated that the program behaves in undesirable ways debugging is the process of searching for an explanation of that behavior the key to being consistently good at debugging is being systematic in conducting that search start by studying the available data this includes the test results and the program text study all of the test results examine not only the tests that revealed the presence of problembut also those tests that seemed to work perfectly trying to understand why one test worked and another did not is often illuminating when looking at the program textkeep in mind that you don' completely understand it if you didthere probably wouldn' be bug nextform hypothesis that you believe to be consistent with all the data the hypothesis could be as narrow as "if change line from to <ythe problem will go awayor as broad as "my program is not terminating because have the wrong exit condition in some while loop nextdesign and run repeatable experiment with the potential to refute the hypothesis for exampleyou might put print statement before and after each while loop if these are always pairedthen the hypothesis that while loop is causing nontermination has been refuted decide before running the experiment how you would interpret various possible results if you wait until on august knight capital groupinc deployed new piece of stock-trading software within forty-five minutes bug in that software lost the company $ , , the next daythe ceo of knight commented that the bug caused the software to enter " ton of ordersall erroneous