debugging unit testing profiling debuggingtestingand profiling |||writing programs is mixture of artcraftand scienceand because it is done by humansmistakes are made fortunatelythere are techniques we can use to help avoid problems in the first placeand techniques for identifying and fixing mistakes when they become apparent mistakes fall into several categories the quickest to reveal themselves and the easiest to fix are syntax errorssince these are usually due to typos more challenging are logical errors--with thesethe program runsbut some aspect of its behavior is not what we intended or expected many errors of this kind can be prevented from happening by using tdd (test driven development)where when we want to add new featurewe begin by writing test for the feature--which will fail since we haven' added the feature yet--and then implement the feature itself another mistake is to create program that has needlessly poor performance this is almost always due to poor choice of algorithm or data structure or both howeverbefore attempting any optimization we should start by finding out exactly where the performance bottleneck lies--since it might not be where we expect--and then we should carefully decide what optimization we want to dorather than working at random in this first section we will look at python' tracebacks to see how to spot and fix syntax errors and how to deal with unhandled exceptions then we will see how to apply the scientific method to debugging to make finding errors as fast and painless as possible we will also look at python' debugging support in the second section we will look at python' support for writing unit testsand in particular the doctest module we saw earlier (in and )and the unittest module we will see how to use these modules to support tdd in the final section we will briefly look at profilingto identify performance hot spots so that we can properly target our optimization efforts