v3 flag enabled
Log In
Log In

Design Best Practices

Design Best Practices

Use these guidelines as recommendations based on past author’s experiences of preparing content for a library submission.

Overview

When designing a new library:

Source Files

Naming

Use the naming conventions of the C++ Standard Library (See https://www.boost.org/doc/contributor-guide/design-guide/design-best-practices.html#_naming_conventions_rationale">Naming Conventions Rationale):

  • Names (except as noted below) should be all lowercase, with words separated by underscores.

  • Acronyms should be treated as ordinary names (e.g. xml_parser instead of XML_parser).

  • Template parameter names begin with an uppercase letter.

  • Macro names 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.

Naming Consistency

As library developers and users have gained experience with Boost, the following consistent naming approach has come to be viewed as helpful, particularly for larger libraries that need their own header subdirectories and namespaces.

  • The library is given a name that describes the contents of the library. Cryptic abbreviations are strongly discouraged. Following the practice of the C++ Standard Library, names are usually singular rather than plural. For example, a library dealing with file systems might chose the name "filesystem", but not "filesystems", "fs" or "nicecode".

  • The library’s primary directory (in parent boost-root/libs) is given that same name. For example, boost-root/libs/filesystem.

  • The library’s primary header directory (in boost-root/libs/name/include) is given that same name. For example, boost-root/libs/filesystem/boost/filesystem.

  • The library’s primary namespace (in parent ::boost) is given that same name, except when there’s a component with that name (e.g., boost::tuple), in which case the namespace name is pluralized. For example, ::boost::filesystem.

  • The first letter of the library name is capitalized.

  • A period between "Boost" and the library name (e.g., Boost.Bind) is used if and only if the library name is not followed by the word "library".

  • The word "library" is not part of the library name and is therefore lowercased.

Here are a few example sentences of how to apply these conventions:

  • "Boost.Bind was written by Peter Dimov."

  • "The Boost Asio library was written by Christopher Kohlhoff."

  • "I regularly use Spirit, a Boost library written by Joel de Guzman and Hartmut Kaiser."

Filenames

Naming requirements ensure that file and directory names are relatively portable, including to ISO 9660:1999 (with extensions) and other relatively limited file systems. Superscript links are provided to detailed rationale for each choice.

  • Names must contain only lowercase ASCII letters ('a'-'z'), numbers ('0'-'9'), underscores ('_'), hyphens ('-'), and periods ('.'). Spaces are not allowed.

    • Some legacy file systems require single-case names. Single-case names eliminate casing mistakes when moving from case-insensitive to case-sensitive file systems.

    • To quote the POSIX standard, "Filenames should be constructed from the portable filename character set because the use of other characters can be confusing or ambiguous in certain contexts."

Next Post

  • Safe C++
    #Compressed Pair
    The lack of memory safety in C++ is identified as creating exploitable vulnerabilities, and the Safe C++ proposal for memory‑safe operations has been placed on indefinite hiatus. Established safe practices are recommended for Boost contributors, unsafe dependencies are to be avoided, and ongoing safety discussions are to be followed. The proposal’s goals are praised in feedback while integration complexity, performance impact, and competition from Rust and Swift are cited as concerns. Recommended reading includes Herb Sutter’s safety‑in‑context blog post and papers on core safety profiles. Boost libraries such as SmartPtr, Pool, StaticAssert, TypeTraits, Filesystem, ScopeExit, Interprocess, Thread, Asio, Atomic, Optional, Variant2, and Coroutine2 are cited as demonstrations of memory, type, resource, and thread safety.
  • Algorithm
    #Algorithm
    An algorithm is defined as a finite sequence of mathematically rigorous logical instructions used to solve a class of specific problems or to perform a computation. It is employed as a specification for calculations and data processing. Conditionals may be incorporated to divert execution along various routes, enabling automated decision‑making and automated reasoning. In contrast, a heuristic is described as an approach that solves problems without well‑defined correct or optimal results. Heuristics are often applied in contexts such as social‑media recommender systems, where no truly correct recommendation exists. The distinction between algorithms and heuristics is therefore highlighted by the presence or absence of guaranteed optimal outcomes. Both concepts are considered fundamental to mathematics and computer science.