Documentation Best Practices

A small set of fresh and accurate docs is better than a large assembly of “documentation” in various states of disrepair.

Write short and useful documents. Cut out everything unnecessary, including out-of-date, incorrect, or redundant information. Also make a habit of continually massaging and improving every doc to suit your changing needs. Docs work best when they are alive but frequently trimmed, like a bonsai tree.

Update Docs with Code

Change your documentation in the same CL as the code change. This keeps your docs fresh, and is also a good place to explain to your reviewer what you’re doing.

A good reviewer can at least insist that docstrings, header files, README.md files, and any other docs get updated alongside the CL.

Delete Dead Documentation

Dead docs are bad. They misinform, they slow down, they incite despair in engineers and laziness in team leads. They set a precedent for leaving behind messes in a code base. If your home is clean, most guests will be clean without being asked.

Just like any big cleaning project, it’s easy to be overwhelmed. If your docs are in bad shape:

Prefer the Good Over the Perfect

Documentation is an art. There is no perfect document, there are only proven methods and prudent guidelines. See Better is better than best.

Documentation is the Story of Your Code

Writing excellent code doesn’t end when your code compiles or even if your test coverage reaches 100%. It’s easy to write something a computer understands, it’s much harder to write something both a human and a computer understand. Your mission as a Code Health-conscious engineer is to write for humans first, computers second. Documentation is an important part of this skill.

There’s a spectrum of engineering documentation that ranges from terse comments to detailed prose:

  1. Meaningful names: Good naming allows the code to convey information that would otherwise be relegated to comments or documentation. This includes nameable entities at all levels, from local variables to classes, files, and directories.
  2. Inline comments: The primary purpose of inline comments is to provide information that the code itself cannot contain, such as why the code is there.
  3. Method and class comments:
  4. README.md: A good README.md orients the new user to the directory and points to more detailed explanation and user guides:

Duplication is Evil

Do not write your own guide to a common Google technology or process. Link to it instead. If the guide doesn’t exist or it’s badly out of date, submit your updates to the appriopriate directory or create a package-level README.md. Take ownership and don’t be shy: Other teams will usually welcome your contributions.