| Home | Libraries | People | FAQ | More

# Boost Library Requirements and Guidelines

This page describes requirements and guidelines for the content of a library submitted to Boost.

See the Boost Library Submission Process page for a description of the process involved.

## Requirements

To avoid the frustration and wasted time of a proposed library being rejected, it must meets these requirements:

- The license must meet the license requirements below. Restricted licenses like the GPL and LGPL are not acceptable.
- The copyright ownership must be clear.
- The library must be generally useful and not restricted to a narrow problem domain.
- The library must meet the portability requirements below.
- The library must come reasonably close to meeting the Guidelines below.
  - Design and Programming
  - Directory Structure
  - Documentation
- The author must be willing to participate in discussions on the mailing list, and to refine the library accordingly.

There's no requirement that an author read the mailing list for a time before making a submission. It has been noted, however, that submissions which begin "I just started to read this mailing list ..." seem to fail, often embarrassingly.

### License requirements

- Must be simple to read and understand.
- Must grant permission to copy, use and modify the software for any use (commercial and non-commercial) for no fee.
- Must require that the license appear on all copies of the software source code.
- Must not require that the license appear with executables or other binary uses of the library.
- Must not require that the source code be available for execution or other binary uses of the library.
- May restrict the use of the name and description of the library to the standard version found on the Boost web site.

### Portability requirements

- A library's interface must portable and not restricted to a particular compiler or operating system.

- A library's implementation must if possible be portable and not restricted to a particular compiler or operating system. If a portable implementation is not possible, non-portable constructions are acceptable if reasonably easy to port to other environments.

- There is no requirement that a library run on C++ compilers which do not conform to the ISO standard.

- There is no requirement that a library run on any particular C++ compiler. Boost contributors often try to ensure their libraries work with popular compilers. The boost/config.hpp configuration header is the preferred mechanism for working around compiler deficiencies.

Since there is no absolute way to prove portability, many boost submissions demonstrate practical portability by compiling and executing correctly with two different C++ compilers, often under different operating systems. Otherwise reviewers may disbelieve that porting is in fact practical.

### Ownership

Are you sure you own the library you are thinking of submitting? "How to Copyright Software" by MJ Salone, Nolo Press, 1990 says:

> Doing work on your own time that is very similar to programming you do for your employer on company time can raise nasty legal problems. In this situation, it's best to get a written release from your employer in advance.

Place a copyright notice in all the important files you submit. Boost.org won't accept libraries without clear copyright information.

## Guidelines

Please use these guidelines as a checklist for preparing the content a library submission. Not every guideline applies to every library, but a reasonable effort to comply is expected.

### Design and Programming

- Aim for ISO Standard C++. Than means making effective use of the standard features of the language, and avoiding non-standard compiler extensions. It also means using the C++ Standard Library where applicable.

- Headers should be good neighbors. See the header policy.

- Follow quality programming practices. See, for example, "Effective C++" 2nd Edition, and "More Effective C++", both by Scott Meyers, published by Addison Wesley.

- Use the C++ Standard Library or other Boost libraries, but only when the benefits outweigh the costs. Do not use libraries other than the C++ Standard Library or Boost. See Library reuse.

- Read Implementation Variation to see how to supply performance, platform, or other implementation variations.

- Use the lowercase/underscore naming conventions of the C++ standard library. Template parameter names begin with an uppercase letter. Macro (gasp!) names should be all uppercase and begin with BOOST_.

- Choose meaningful names - explicit is better than implicit, and readability counts. There is a strong preference for clear and descriptive names, even if lengthy.

- Use exceptions to report errors where appropriate, and write code that is safe in the face of exceptions.

- Avoid exception-specifications. See exception-specification rationale.

- Provide sample programs or confidence tests so potential users can see how to use your library.

- Provide a regression test program or programs which follow the Test Policies and Protocols.

- Although some boost members use proportional fonts, tabs, and unrestricted line lengths in their own code, boost's widely distributed source code should follow more conservative guidelines:
  - Use fixed-width fonts. See fonts rationale.
  - Use spaces rather than tabs.
  - Limit line lengths to 80 characters.

- Begin all source files with:
  - A comment line describing the contents of the file.
  - Comments describing copyright and licensing.
  - A comment line referencing the Boost home page in the form:
    `// See http://www.boost.org for updates, documentation, and revision history.`
    [Including revision history in source files is no longer recommended; the publicly available CVS repository better serves that purpose.]

### Directory Structure

- All libraries have at their highest level a primary directory named for the particular library. The primary directory may have sub-directories.
- For very simple libraries implemented entirely within the library header, all files go in the primary directory (except headers, which go in the boost header directory).

> Boost standard sub-directory names

> Sub-directory | Contents | Required
> `build` | Library build files such as make files or IDE project files. | If any build files.
> doc | Documentation (HTML) files. | If several doc files.
> `example` | Sample program files. | If several sample files.
> `src` | Source files which must be compiled to build the library. | If any source files.
> `test` | Regression or other test programs or scripts. | If several test files.

### Documentation

Even the simplest library needs some documentation; the amount should be proportional to the need. The documentation should assume the readers have a basic knowledge of C++, but are not necessarily experts.

The format for documentation should be HTML, and should not require an advanced browser or server-side extensions.

There is no single right way to do documentation. HTML documentation is often organized quite differently from traditional printed documents. Task-oriented styles differ from reference oriented styles. In the end, it comes down to the question: Is the documentation sufficient for the mythical "average" C++ programmer to use the library successfully?

Appropriate topics for documentation often include:

- General introduction to the library.
- Description of each class.
- Relationship between classes.
- For each function, as applicable, description, requirements (preconditions), effects, post-conditions, returns, and throws.
- Discussion of error detection and recovery strategy.
- How to use including description of typical uses.
- How to compile and link.
- How to test.
- Version or revision history.
- Rationale for design decisions. See Rationale rationale.
- Acknowledgements. See Acknowledgments rationale.

## Rationale

Rationale for some of the requirements and guidelines follows.

### Exception-specification rationale

Exception specifications [ISO 15.4] are sometimes coded to indicate what exceptions may be thrown, or because the programmer hopes they will improved performance. But consider the follow member from a smart pointer:

        T& operator*() const throw()  { return *ptr; }

This function calls no other functions; it only manipulates fundamental data types like pointers Therefore, no runtime behavior of the exception-specification can ever be invoked. The function is completely exposed to the compiler; indeed it is declared inline Therefore, a smart compiler can easily deduce that the functions are incapable of throwing exceptions, and make the same optimizations it would have made based on the empty exception-specification. A "dumb" compiler, however, may make all kinds of pessimizations.

For example, some compilers turn off inlining if there is an exception-specification. Some compilers add try/catch blocks. Such pessimizations can be a performance disaster which makes the code unusable in practical applications.

Although initially appealing, an exception-specification tends to have consequences that require very careful thought to understand. The biggest problem with exception-specifications is that programmers use them as though they have the effect the programmer would like, instead of the effect they actually have.

A non-inline function is the one place a "throws nothing" exception-specification may have some benefit with some compilers.

### Naming conventions rationale

The C++ standard committee's Library Working Group discussed this issue in detail, and over a long period of time. The discussion was repeated again in early boost postings. A short summary:

- Naming conventions are contentious, and although several are widely used, no one style predominates.
- Given the intent to propose portions of boost for the next revision of the C++ standard library, boost decided to follow the standard library's conventions.
- Once a library settles on a particular convention, a vast majority of stakeholders want that style to be consistently used.

### Source code fonts rationale

Dave Abrahams comments: An important purpose (I daresay the primary purpose) of source code is communication: the documentation of intent. This is a doubly important goal for boost, I think. Using a fixed-width font allows us to communicate with more people, in more ways (diagrams are possible) right there in the source. Code written for fixed-width fonts using spaces will read reasonably well when viewed with a variable-width font, and as far as I can tell every editor supporting variable-width fonts also supports fixed width. I don't think the converse is true.

### Rationale rationale

Rationale is defined as "The fundamental reasons for something; basis." by the American Heritage Dictionary.

Beman Dawes comments: Failure to supply contemporaneous rationale for design decisions is a major defect in many software projects. Lack of accurate rationale causes issues to revisited endlessly, causes maintenance bugs when a maintainer changes something without realizing it was done a certain way for some purpose, and shortens the useful lifetime of software.

Rationale is fairly easy to provide at the time decisions are made, but very hard to accurately recover even a short time later.

### Acknowledgements rationale

As a library matures, it almost always accumulates improvements suggested to the authors by other boost members. It is a part of the culture of boost.org to acknowledge such contributions, identifying the person making the suggestion. Major contributions are usually acknowledged in the documentation, while minor fixes are often mentioned in comments within the code itself.

Revised 06 February, 2001