The Practice of Programming by Brian W. Kernighan & Rob Pike

The Practice of Programming by Brian W. Kernighan & Rob Pike

Author:Brian W. Kernighan & Rob Pike
Language: eng
Format: epub
Publisher: Addison-Wesley
Published: 1999-07-14T16:00:00+00:00


5.7. Other People’s Bugs

Realistically, most programmers do not have the fun of developing a brand new system from the ground up. Instead, they spend much of their time using, maintaining, modifying and thus, inevitably, debugging code written by other people.

When debugging others’ code, everything that we have said about how to debug your own code applies. Before starting, though, you must first acquire some understanding of how the program is organized and how the original programmers thought and wrote. The term used in one very large software project is “discovery,” which is not a bad metaphor. The task is discovering what on earth is going on in something that you didn’t write.

This is a place where tools can help significantly. Text-search programs like grep can find all the occurrences of names. Cross-referencers give some idea of the program’s structure. A display of the graph of function calls is valuable if it isn’t too big. Stepping through a program a function call at a time with a debugger can reveal the sequence of events. A revision history of the program may give some clues by showing what has been done to the program over time. Frequent changes are often a sign of code that is poorly understood or subject to changing requirements, and thus potentially buggy.

Sometimes you need to track down errors in software you are not responsible for and do not have the source code for. In that case, the task is to identify and characterize the bug sufficiently well that you can report it accurately, and at the same time perhaps find a “work-around” that avoids the problem.

If you think that you have found a bug in someone else’s program, the first step is to make absolutely sure it is a genuine bug, so you don’t waste the author’s time and lose your own credibility.

When you find a compiler bug, make sure that the error is really in the compiler and not in your own code. For example, whether a right shift operation fills with zero bits (logical shift) or propagates the sign bit (arithmetic shift) is unspecified in C and C++, so novices sometimes think it’s an error if a construct like

Click here to view code image

? i = -1;

? printf("%d\n", i >> 1);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.