Go to the first, previous, next, last section, table of contents.

# Documenting Programs

- GNU Manuals: Writing proper manuals.
- Manual Structure Details: Specific structure conventions.
- NEWS File: NEWS files supplement manuals.
- Change Logs: Recording Changes
- Man Pages: Man pages are secondary.
- Reading other Manuals: How far you can go in learning from other manuals.

## GNU Manuals

The preferred way to document part of the GNU system is to write a manual in the Texinfo formatting language. See the Texinfo manual, either the hardcopy, or the on-line version available through `info` or the Emacs Info subsystem (`C-h i`).

Programmers often find it most natural to structure the documentation following the structure of the implementation, which they know. But this structure is not necessarily good for explaining how to use the program; it may be irrelevant and confusing for a user.

At every level, from the sentences in a paragraph to the grouping of topics into separate manuals, the right way to structure documentation is according to the concepts and questions that a user will have in mind when reading it. Sometimes this structure of ideas matches the structure of the implementation of the software being documented--but often they are different. Often the most important part of learning to write good documentation is learning to notice when you are structuring the documentation like the implementation, and think about better alternatives.

For example, each program in the GNU system probably ought to be documented in one manual; but this does not mean each program should have its own manual. That would be following the structure of the implementation, rather than the structure that helps the user understand.

Instead, each manual should cover a coherent topic. For example, instead of a manual for `diff` and a manual for `diff3`, we have one manual for "comparison of files" which covers both of those programs, as well as `cmp`. By documenting these programs together, we can make the whole subject clearer.

The manual which discusses a program should document all of the program's command-line options and all of its commands. It should give examples of their use. But don't organize the manual as a list of features. Instead, organize it logically, by subtopics. Address the questions that a user will ask when thinking about the job that the program does.

In general, a GNU manual should serve both as tutorial and reference. It should be set up for convenient access to each topic through Info, and for reading straight through (appendixes aside). A GNU manual should give a good introduction to a beginner reading through from the start, and should also provide all the details that hackers want.

That is not as hard as it first sounds. Arrange each chapter as a logical breakdown of its topic, but order the sections, and write their text, so that reading the chapter straight through makes sense. Do likewise when structuring the book into chapters, and when structuring a section into paragraphs. The watchword is, at each point, address the most fundamental and important issue raised by the preceding text.

If necessary, add extra chapters at the beginning of the manual which are purely tutorial and cover the basics of the subject. These provide the framework for a beginner to understand the rest of the manual. The Bison manual provides a good example of how to do this.

Don't use Unix man pages as a model for how to write GNU documentation; most of them are terse, badly structured, and give inadequate explanation of the underlying concepts. (There are, of course exceptions.) Also Unix man pages use a particular format which is different from what we use in GNU manuals.

Please do not use the term "pathname" that is used in Unix documentation; use "file name" (two words) instead. We use the term "path" only for search paths, which are lists of file names.

Please do not use the term "illegal" to refer to erroneous input to a computer program. Please use "invalid" for this, and reserve the term "illegal" for violations of law.

## Manual Structure Details

The title page of the manual should state the version of the programs or packages documented in the manual. The Top node of the manual should also contain this information. If the manual is changing more frequently than or independent of the program, also state a version number for the manual in both of these places.

Each program documented in the manual should should have a node named ``program Invocation'` or ``Invoking program'`. This node (together with its subnodes, if any) should describe the program's command line arguments and how to run it (the sort of information people would look in a man page for). Start with an ``@example'` containing a template for all the options and arguments that the program uses.

Alternatively, put a menu item in some menu whose item name fits one of the above patterns. This identifies the node which that item points to as the node for this purpose, regardless of the node's actual name.

There will be automatic features for specifying a program name and quickly reading just this part of its manual.

If one manual describes several programs, it should have such a node for each program described.

## The NEWS File

In addition to its manual, the package should have a file named ``NEWS'` which contains a list of user-visible changes worth mentioning. In each new release, add items to the front of the file and identify the version they pertain to. Don't discard old items; leave them in the file after the newer items. This way, a user upgrading from any previous version can see what is new.

If the ``NEWS'` file gets very long, move some of the older items into a file named ``ONEWS'` and put a note at the end referring the user to that file.

## Change Logs

Keep a change log to describe all the changes made to program source files. The purpose of this is so that people investigating bugs in the future will know about the changes that might have introduced the bug. Often a new bug can be found by looking at what was recently changed. More importantly, change logs can help you eliminate conceptual inconsistencies between different parts of a program, by giving you a history of how the conflicting concepts arose and who they came from.

- Change Log Concepts
- Style of Change Logs
- Simple Changes
- Conditional Changes

### Change Log Concepts

You can think of the change log as a conceptual "undo list" which explains how earlier versions were different from the current version. People can see the current version; they don't need the change log to tell them what is in it. What they want from a change log is a clear explanation of how the earlier version differed.

The change log file is normally called ``ChangeLog'` and covers an entire directory. Each directory can have its own change log, or a directory can use the change log of its parent directory--it's up to you.

Another alternative is to record change log information with a version control system such as RCS or CVS. This can be converted automatically to a ``ChangeLog'` file.

There's no need to describe the full purpose of the changes or how they work together. If you think that a change calls for explanation, you're probably right. Please do explain it--but please put the explanation in comments in the code, where people will see it whenever they see the code. For example, "New function" is enough for the change log when you add a function, because there should be a comment before the function definition to explain what it does.

However, sometimes it is useful to write one line to describe the overall purpose of a batch of changes.

The easiest way to add an entry to ``ChangeLog'` is with the Emacs command `M-x add-change-log-entry`. An entry should have an asterisk, the name of the changed file, and then in parentheses the name of the changed functions, variables or whatever, followed by a colon. Then describe the changes you made to that function or variable.

### Style of Change Logs

Here are some examples of change log entries:

    * register.el (insert-register): Return nil.
    (jump-to-register): Likewise.

    * sort.el (sort-subr): Return nil.

    * tex-mode.el (tex-bibtex-file, tex-file, tex-region):
    Restart the tex shell if process is gone or stopped.
    (tex-shell-running): New function.

    * expr.c (store_one_arg): Round size up for move_block_to_reg.
    (expand_call): Round up when emitting USE insns.
    * stmt.c (assign_parms): Round size up for move_block_from_reg.

It's important to name the changed function or variable in full. Don't abbreviate function or variable names, and don't combine them. Subsequent maintainers will often search for a function name to find all the change log entries that pertain to it; if you abbreviate the name, they won't find it when they search.

For example, some people are tempted to abbreviate groups of function names by writing ``* register.el ({insert,jump-to}-register)'`; this is not a good idea, since searching for `jump-to-register` or `insert-register` would not find that entry.

Separate unrelated change log entries with blank lines. When two entries represent parts of the same change, so that they work together, then don't put blank lines between them. Then you can omit the file name and the asterisk when successive entries are in the same file.

### Simple Changes

Certain simple kinds of changes don't need much detail in the change log.

When you change the calling sequence of a function in a simple fashion, and you change all the callers of the function, there is no need to make individual entries for all the callers that you changed. Just write in the entry for the function being called, "All callers changed."

    * keyboard.c (Fcommand_execute): New arg SPECIAL.
    All callers changed.

When you change just comments or doc strings, it is enough to write an entry for the file, without mentioning the functions. Just "Doc fixes" is enough for the change log.

There's no need to make change log entries for documentation files. This is because documentation is not susceptible to bugs that are hard to fix. Documentation does not consist of parts that must interact in a precisely engineered fashion. To correct an error, you need not know the history of the erroneous passage; it is enough to compare what the documentation says with the way the program actually works.

### Conditional Changes

C programs often contain compile-time `#if` conditionals. Many changes are conditional; sometimes you add a new definition which is entirely contained in a conditional. It is very useful to indicate in the change log the conditions for which the change applies.

Our convention for indicating conditional changes is to use square brackets around the name of the condition.

Here is a simple example, describing a change which is conditional but does not have a function or entity name associated with it:

    * xterm.c [SOLARIS2]: Include string.h.

Here is an entry describing a new definition which is entirely conditional. This new definition for the macro `FRAME_WINDOW_P` is used only when `HAVE_X_WINDOWS` is defined:

    * frame.h [HAVE_X_WINDOWS] (FRAME_WINDOW_P): Macro defined.

Here is an entry for a change within the function `init_display`, whose definition as a whole is unconditional, but the changes themselves are contained in a ``#ifdef HAVE_LIBNCURSES'` conditional:

    * dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent.

Here is an entry for a change that takes affect only when a certain macro is not defined:

    (gethostname) [!HAVE_SOCKETS]: Replace with winsock version.

## Man Pages

In the GNU project, man pages are secondary. It is not necessary or expected for every GNU program to have a man page, but some of them do. It's your choice whether to include a man page in your program.

When you make this decision, consider that supporting a man page requires continual effort each time the program is changed. The time you spend on the man page is time taken away from more useful work.

For a simple program which changes little, updating the man page may be a small job. Then there is little reason not to include a man page, if you have one.

For a large program that changes a great deal, updating a man page may be a substantial burden. If a user offers to donate a man page, you may find this gift costly to accept. It may be better to refuse the man page unless the same person agrees to take full responsibility for maintaining it--so that you can wash your hands of it entirely. If this volunteer later ceases to do the job, then don't feel obliged to pick it up yourself; it may be better to withdraw the man page from the distribution until someone else agrees to update it.

When a program changes only a little, you may feel that the discrepancies are small enough that the man page remains useful without updating. If so, put a prominent note near the beginning of the man page explaining that you don't maintain it and that the Texinfo manual is more authoritative. The note should say how to access the Texinfo documentation.

## Reading other Manuals

There may be non-free books or documentation files that describe the program you are documenting.

It is ok to use these documents for reference, just as the author of a new algebra textbook can read other books on algebra. A large portion of any non-fiction book consists of facts, in this case facts about how a certain program works, and these facts are necessarily the same for everyone who writes about the subject. But be careful not to copy your outline structure, wording, tables or examples from preexisting non-free documentation. Copying from free documentation may be ok; please check with the FSF about the individual case.

Go to the first, previous, next, last section, table of contents.