This lecture provides an introduction to debugging, a crucial activity in every developer's life. After an elementary discussion of some useful debugging concepts, the lecture goes on with a detailed review of general debugging techniques, independent of any specific software. The final part of the lecture is dedicated to analysing problems related to the use of C++ , the main programming language commonly employed in particle physics nowadays.
1. General concepts
about debugging. After many days of brainstorming, designing and coding, the programmer finally have a wonderful piece of code. He compiles it and runs it. Everything seems pretty straightforward but unfortunately it doesn't work! And now? Now the great fun starts! Time to dig into the wonderful world of debugging. Despite being the realm of ingenuity and uncertainty, a debugging process can be divided into four main steps:
1. localising a bug,
2. classifying a bug,
3. understanding a bug,
4. repairing a bug.
1.1 Localizing a bug
A typical attitude of inexperienced programmers towards bugs is to consider their localization an easy task: they notice their code does not do what they expected, and they are led astray by their confidence in knowing what their code should do. This confidence is completely deceptive because spotting a bug can be very difficult. As it was explained in the introduction, all bugs stem from the premise that something thought to be right, was in fact wrong.
Noticing a bug implies testing. Testing should be performed with discipline and, when possible, automatically, for example after each build of the code. In case of a test failure, the programmer must be able to see what went wrong easily, so tests must be prepared carefully. This lecture will not cover the basic of testing.