| [ Team LiB ] |
8.4 Additional Documentation SourcesWhen looking for source code documentation, consider nontraditional sources such as comments, standards, publications, test cases, mailing lists, newsgroups, revision logs, issue-tracking databases, marketing material, and the source code itself. When investigating a large body of code, it is natural to miss documentation embedded in comments in the quest for more formal sources such as requirements and design documents. Yet source code comments are often better maintained than the corresponding formal documents and often hide gems of information, sometimes even including elaborate ASCII diagrams. As an example, the diagrams in Figure 8.3 and the formal mathematical proof in Figure 8.4[44] are all excerpts from actual source code comments. The ASCII diagrams depict the block structure of an audio interface hardware[45] (top left), the logical channel reshuffling procedure in X.25 networking code[46] (top right), the m4 macro processor stack-based data structure[47] (bottom left), and the page format employed in the hashed db database implementation[48] (bottom right). However, keep in mind that elaborate diagrams such as these are rarely kept up-to-date when the code changes.
Figure 8.3. ASCII drawings in source code comments.Always view documentation with a critical mind. Since documentation is never executed and rarely tested or formally reviewed to the extent code is, it can often be misleading or outright wrong. As an example, consider some of the problems[49] of the comment in Figure 8.4.
A nontraditional documentation element, intimately bound to the source code, is the revision control system. This repository contains a detailed history of the source code's evolution and, often, comments justifying each change. In Section 6.5 we examine how you can benefit from using such a system when reading code. Associated with a revision control system is also often an issue-tracking database. There you will find details of bug reports, change requests, and other maintenance documentation. When these originate from inside the development organization, they may provide background on design and implementation issues related to the code you are reading. The tautology may appear to be an oxymoron, but the source code can sometimes be its own documentation. Apart from the obvious case of self-documenting code, sometimes you can read code between the lines as a specification, even if the actual code does not implement the underlying intention of what the code should actually do. Consider the following (trivial) shell-script excerpt.[50]
The code will display each one of the space-separated arguments appearing in the $* list on a separate line. It is obvious, however, from the loop structure that the intention of the code is to display each file name in the $* list on a separate line. Although the file variable should more appropriately have been named filename, and the code will not work correctly when file names contain whitespace, you can still read the code as the specification of what it should do, rather than what it actually claims it does. Finally, you can often find additional documentation on the periphery or outside the development organization. Standards documents can be treated as the functional specification for software that implements a specific standard (for example, an MP3 player).Similarly, you can often find a description of a given design, system, algorithm, or implementation in journal or conference publications. If verification and validation are handled by a separate test group, you can use their test cases as a substitute or a supplement of a functional specification. When desperate, even marketing material can provide you with an (inflated) list of a system's features. And you can always search the Web for discussions, unofficial information, FAQ pages, and user experiences; archived newsgroups and mailing lists may sometimes reveal the rationale behind the design of the code you are reading. When the code is open-source, a particularly effective search strategy is to use three or four nonword identifiers from the code part you are reading (for example, bbp, indouble, addch) as search terms in a major search engine. Open-source code also provides you with the option to contact the code's original author. Try not to abuse this privilege, and be sure to give something back to the community for any help you receive in this way. Remember: most open-source projects are developed and maintained by (typically overworked) volunteers. Exercise 8.13 |
| [ Team LiB ] |
0 comments:
Post a Comment