Documentation - Friend or Foe?

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

You may think the Y2K problem was the biggest blunder of the information economy, or you may think it was unavoidable and cost-justified because of all the storage saved when disk space, memory, and processing power were so expensive. No matter what you think about the Y2K problem, we all learned a valuable lesson having lived through it: Development documentation can make IT projects easier or break them.

Y2K fixes are child’s play to implement. The mammoth task is finding all the places where a change is needed. Good documentation, if we have it, can speed up Y2K fixes considerably because finding Y2K bugs comprises some 50 percent of the Y2K work. In this article, I will share with you some of my thoughts (and experiences) on what good documentation is and how to go about generating it.

Why Is Good Documentation So Rare?

First, I must dispel one key myth about documentation—namely, that documentation is simply commenting code. (When I refer to documentation, I am talking about development documentation, not end-user documentation such as help text or manuals.) I suspect that many developers, if quizzed directly, would quickly acknowledge that there is much more to documentation than good comments, but it is surprising how often the only form of documentation is the comments in the code. Even more surprising is the dubious quality of both the comments and other forms of documentation for the programs companies write. Maybe that’s because of the old saying that “real” programmers don’t write documentation because if the code was difficult to write, it should be difficult to read. However, as hard as it was to write the code, it turns out it’s even harder to change it. Just ask a Y2K project manager.

Joking aside, there are many practical reasons that even the little documentation we sometimes have for an application is of poor quality and of little use:

• Documentation is rarely a part of the project plans and schedules. Partly because it is a user deliverable, partly because it is typically done by specialized personnel (technical writers), end-user documentation is a separate project, while internal documentation remains an implicit item on a developer’s plate. As a result, documentation is the lowest item on the totem pole, even lower than testing. When testing gets squeezed between unrealistic estimates and inflexible schedules, guess what happens to documentation?

• Documentation and code quickly get out of sync. There are two ways this problem can happen. First, some (or all) of the documentation is not where the code is, so the code gets changed, but the corresponding documentation doesn’t. Second, the deadline pressures for code changes are often even higher than for base development and, therefore, are often subject to even less process and scrutiny.

• Documentation is usually written by somebody who knows the code inside and out. As all of us who went to school know, it is one thing to know your stuff and altogether a different thing to explain it well to others. There are two major consequences to that. First, it is hard to separate what one can reasonably assume to be known from what needs to be explicitly stated. Intimate involvement in developing the code tends to raise the number of assumptions, simply because of familiarity with the subject. What is clear to someone who has been working for months on a particular application may not be at all evident to a less seasoned developer. Second, programmers tend to document what a programming statement does rather than what it means. Have you ever seen C code like this?

Counter++; /* Add one to Counter *
Wouldn’t something like this be much better?

Counter++; /* Advance to the next product description */

Four Steps to Better Documentation

Any project is more likely to get done properly when responsibility, which goes hand in hand with accountability, is clearly defined. With that in mind, I recommend the following:

1. Identify documentation deliverables in your project plans. Expectations have to be clearly set. Your development process definition should include a definition of the documentation that must be delivered, and project plans might simply refer to your process description.

2. On your project schedules, identify specific documentation tasks and allocate time for them. Setting aside time on the schedule specifically for documentation helps separate it from programming and indicates that this work will be tracked like any other task.

3. Inspect documentation at all inspection stages just as you do with other project deliverables. All too often, documentation is left until the end of the development cycle on the grounds that code will change anyway. The idea is to save effort by writing the documentation only once, after the code is finalized. Sounds wonderful in theory. In practice, it means you just kissed good-bye any chance of getting decent documentation! Yes, the code will change, so the documentation will need to change, too. Consider this documentation process a dress rehearsal for the many years of application support to come. Programmers need to get used to keeping code and documentation in sync, and diligence in documenting code changes will help structure the documentation in a way that will make maintenance (of both documentation and code) less painful.

4. Involve developers who are unfamiliar with the project in the documentation inspection process. For good and valid reasons, code inspections should be done by developers who understand the code very well. Documentation inspections, however, should be performed by someone outside the project because, invariably, some rookie will end up supporting the application. How easy will it be for this person to understand what the code does? Why not get an early answer to this question rather than wait until you have an emergency to find out? If a separate team in your organization does support, involve them early. Your support team will have to become familiar with the new applications anyway, so it is not a question of if, but it is a question of when.

What Is Good Documentation?

Now that I’ve taken a look at how to get good documentation, it is time to try to answer the age-old question: What exactly constitutes good documentation?

Good documentation is complete, easy-to-maintain application information that helps ensure that changes to the application can be done without causing regression problems.

As I mentioned earlier, many people think documentation means programming comments. However, depending on the nature of the change being contemplated, it is often necessary to understand the general design and even the original requirements for that area of the application. Just about any professional programming shop has requirements and design documents for its code, but how many of those documents are still current a few years down the road? Failing to keep documentation current is a mistake that accounts for a lot of regression problems.

Here are some code change scenarios that could really use requirements and design documents:

• Enhancing performance. Going for performance improvements is always tricky. First, performance-enhancing changes tend to make the code more obscure, more difficult to understand. It is essential to document why the performance enhancement was needed, what changes were made to increase performance, under what assumptions the performance gain will materialize, and what the original code was. Second, since getting better performance usually means changing the way things are done in some fairly fundamental way, it is essential to consult design documents (to understand what implications changing the new design might have elsewhere) and requirements documents (to ensure that the new design will deliver on all the requirements).

• Changing the existing behavior of the application. This is a classic! One person’s bug is another’s feature. Every time I made a requested application change in response to a bug report stating that an application did something wrong, I promptly found somebody crying foul because the old way was better. When you change the behavior of an application, it is particularly important to understand what the originally intended behavior was and whether similar functionality with similar behavior exists elsewhere in the application. The requirements and design documents are invaluable in these cases. Even then, you are likely to be better off implementing a change as an optional behavior, but that’s another story altogether.

• Adding new functionality for additional requirements. This scenario arises frequently if for no other reason than that one way of meeting deadlines is to trim the requirements and leave them for a future release. Chances are that by the time you get around to implementing the leftovers, lots of code will have changed, new people may be working on the product, and so forth. To integrate a new function correctly, it is essential to understand an application’s existing requirements and its design. Unfortunately, reading the code is a very unreliable method for achieving functional understanding of an application!

For these and many other reasons, it is important to have requirements and design documents. It follows, therefore, that maintaining them is important, too.

It is a fact of life that the bulk of the documentation is in the code. This part of the documentation has the advantage of being in front of programmers’ eyes as they work on changing an application, making reading it unavoidable. It is therefore extremely important to make the most of this documentation.

I live by the principle that the best commented code is self-documenting code. The major advantage of self-documenting code is that it keeps code and documentation changes in sync. Self-documenting code is based on the principles of naming conventions and programming standards.

Naming conventions have changed. Most modern programming languages allow very long variable and function names. That’s not only because memory is so cheap these days; it’s also because long names enhance comprehensibility. So don’t be a lazy typist; make use of this capability. A name that fully describes the role of the underlying item may

take longer to type, but it is much easier to understand. A lot can go into a name. Naming conventions can help you understand at a glance where the item is defined (e.g., program module, library, or directory), how the item is defined (e.g., static vs. dynamic storage, local vs. global, or data vs. function type), and how the item is used (e.g., function returning a value, constant, or read-only).

Programming standards help document code in two ways. First, each code structure includes templates that define the basic information to be provided, such as a general description of what the code does, what must hold true for the code to execute correctly (i.e., assumptions), and what will hold true after the code has executed (i.e., results). Second, standard code layouts help the reader understand the code. There is a reason that you can find the fridge at night in the dark. It’s that everything in your house is always in the same place. This aspect of understanding code is frequently ignored, yet research consistently shows that good programming standards, particularly when aided by visual cues (colors, fonts, etc.), can enhance the understandability of code by as much as 20 percent.

Following these suggestions will help you generate good documentation, but it will not cover one essential kind of information about your application: the things learned during application support. This information includes the pitfalls you can fall into and tips on how to avoid them, areas of code that are particularly dangerous (such as certain performance techniques), and other tidbits. This type of information can and should be documented in the code itself, but often enough, there is no good place to put it. A good way to avoid repeating the mistakes of the past is to keep a support checklist with this information and insist that consulting it be part of the support process.

Last, but not least, you need process documentation. Of course, it can be argued that process is not part of the application, but particularly during support activities, following process guidelines can make the difference between chaos and regression-free code fixes and upgrades. A good process may not be enough to ensure quality code changes, but the lack of a good process makes regression problems likely. A good process must also be well-known by its users, and updates to it must be easy to publish and distribute to programmers. That takes us back to the support checklist, which can play one final role. It can be a flowchart on how to make changes to the application, with pointers to various process documents in the proper places, acting, in a sense, as a process map guiding programmers step by step on how to make required changes while avoiding potential traps.

BLOG COMMENTS POWERED BY DISQUS