[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Documenting Programs

A GNU program should ideally come with full free documentation, adequate for both reference and tutorial purposes. If the package can be programmed or extended, the documentation should cover programming or extending it, as well as just using it.

6.1 GNU Manuals  Writing proper manuals.
6.2 Doc Strings and Manuals  Compiling doc strings doesn't make a manual.
6.3 Manual Structure Details  Specific structure conventions.
6.4 License for Manuals  Writing the distribution terms for a manual.
6.5 Manual Credits  Giving credit to documentation contributors.
6.6 Printed Manuals  Mentioning the printed manual.
6.7 The NEWS File  NEWS files supplement manuals.
6.8 Change Logs  Recording Changes
6.9 Man Pages  Man pages are secondary.
6.10 Reading other Manuals  How far you can go in learning from other manuals.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 GNU Manuals

The preferred document format for the GNU system is the Texinfo formatting language. Every GNU package should (ideally) have documentation in Texinfo both for reference and for learners. Texinfo makes it possible to produce a good quality formatted book, using TeX, and to generate an Info file. It is also possible to generate HTML output from Texinfo source. See the Texinfo manual, either the hardcopy, or the on-line version available through info or the Emacs Info subsystem (C-h i).

Nowadays some other formats such as Docbook and Sgmltexi can be converted automatically into Texinfo. It is ok to produce the Texinfo documentation by conversion this way, as long as it gives good results.

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 certainly 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. The Bison manual is a good example of this--please take a look at it to see what we mean.

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.

To serve as a reference, a manual should have an Index that list all the functions, variables, options, and important concepts that are part of the program. One combined Index should do for a short manual, but sometimes for a complex package it is better to use multiple indices. The Texinfo manual includes advice on preparing good index entries, see section `Making Index Entries' in The GNU Texinfo Manual, and see section `Defining the Entries of an Index' in The GNU Texinfo manual.

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, some exceptions.) Also, Unix man pages use a particular format which is different from what we use in GNU manuals.

Please include an email address in the manual for where to report bugs in the manual.

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 directory 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 activities punishable by law.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 Doc Strings and Manuals

Some programming systems, such as Emacs, provide a documentation string for each function, command or variable. You may be tempted to write a reference manual by compiling the documentation strings and writing a little additional text to go around them--but you must not do it. That approach is a fundamental mistake. The text of well-written documentation strings will be entirely wrong for a manual.

A documentation string needs to stand alone--when it appears on the screen, there will be no other text to introduce or explain it. Meanwhile, it can be rather informal in style.

The text describing a function or variable in a manual must not stand alone; it appears in the context of a section or subsection. Other text at the beginning of the section should explain some of the concepts, and should often make some general points that apply to several functions or variables. The previous descriptions of functions and variables in the section will also have given information about the topic. A description written to stand alone would repeat some of that information; this redundance looks bad. Meanwhile, the informality that is acceptable in a documentation string is totally unacceptable in a manual.

The only good way to use documentation strings in writing a good manual is to use them as a source of information for writing good text.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3 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 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.

The `--usage' feature of the Info reader looks for such a node or menu item in order to find the relevant text, so it is essential for every Texinfo file to have one.

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

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4 License for Manuals

Please use the GNU Free Documentation License for all GNU manuals that are more than a few pages long. Likewise for a collection of short documents--you only need one copy of the GNU FDL for the whole collection. For a single short document, you can use a very permissive non-copyleft license, to avoid taking up space with a long license.

See http://www.gnu.org/copyleft/fdl-howto.html for more explanation of how to employ the GFDL.

Note that it is not obligatory to include a copy of the GNU GPL or GNU LGPL in a manual whose license is neither the GPL nor the LGPL. It can be a good idea to include the program's license in a large manual; in a short manual, whose size would be increased considerably by including the program's license, it is probably better not to include it.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.5 Manual Credits

Please credit the principal human writers of the manual as the authors, on the title page of the manual. If a company sponsored the work, thank the company in a suitable place in the manual, but do not cite the company as an author.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6 Printed Manuals

The FSF publishes some GNU manuals in printed form. To encourage sales of these manuals, the on-line versions of the manual should mention at the very start that the printed manual is available and should point at information for getting it--for instance, with a link to the page http://www.gnu.org/order/order.html. This should not be included in the printed manual, though, because there it is redundant.

It is also useful to explain in the on-line forms of the manual how the user can print out the manual from the sources.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.7 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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8 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.

6.8.1 Change Log Concepts  
6.8.2 Style of Change Logs  
6.8.3 Simple Changes  
6.8.4 Conditional Changes  
6.8.5 Indicating the Part Changed  

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8.1 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 using rcs2log; in Emacs, the command C-x v a (vc-update-change-log) does the job.

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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8.2 Style of Change Logs

Here are some simple examples of change log entries, starting with the header line that says who made the change and when, followed by descriptions of specific changes. (These examples are drawn from Emacs and GCC.)

1998-08-17  Richard Stallman  <rms@gnu.org>

* 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.

Break long lists of function names by closing continued lines with `)', rather than `,', and opening the continuation with `(' as in this example:

* keyboard.c (menu_bar_items, tool_bar_items)
(Fexecute_extended_command): Deal with `keymap' property.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8.3 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 to use the new calling sequence, 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"---like this:

* 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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8.4 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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8.5 Indicating the Part Changed

Indicate the part of a function which changed by using angle brackets enclosing an indication of what the changed part does. Here is an entry for a change in the part of the function sh-while-getopts that deals with sh commands:

* progmodes/sh-script.el (sh-while-getopts) <sh>: Handle case that
user-specified option string is empty.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.9 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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.10 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.

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on August, 3 2012 using texi2html