7.10 Electronic Archaeology
Unfortunately, most programmers
don't start a project at the design step. Instead
they are immediately thrust into the maintenance or revision stage.
This means most programmers are faced with the worst possible job:
understanding and modifying someone else's code.
Contrary to popular belief, most C++ programs are not written by
disorganized orangutans using Zen programming techniques and poorly
commented in Esperanto. They just look that way. Electronic
archeology is the art of digging through old code to discover amazing
things (like how and why the code works).
Your computer can aid greatly in your search to discover the true
meaning of someone else's code. Many tools are
available for examining and formatting code. Some of these tools
include:
- Cross-referencers
-
These programs have names like xref,
cxref, and cross. System V Unix
has the utility cscope. They print out a list of
variables and where the variables are used.
- Program indenters
-
Programs such as cb and indent
indent a program "correctly"
(correct indentation is something defined by the tool maker).
- Pretty printers
-
A pretty printer such as vgrind or
cprint typesets source code for printing on a
laser printer.
- Call graphs
-
On System V Unix, the program cflow analyzes the
structure of a program. On other systems there is a public domain
utility, calls, that produces call graphs, showing
who calls whom and who is called by whom.
-
Class browsers
-
A class browser allows you to display the class hierarchy so you can
tell what components went into building the class, as well as its
structure. You'll learn what a class is in Chapter 13.
- IDEs
-
Both Borland-C++ Builder and Microsoft Visual C++ .NET contain an
integrated development environment (IDE). This means that the tool
has both an editor and source browsing tools built in. Commercial and
free IDEs are available for Unix as well. One of the better free ones
is Source Navigator, which can be obtained from http://sources.redhat.com/sourcenav (Appendix E gives the location of this
and many other freely available tools).
Which tools should you use? Whichever ones work for you. Different
programmers work in different ways. Some techniques for examining
code are listed in the following sections. Choose the ones that work
for you and use them.
|