title |
---|
opinionated documentation |
This guide outlines some principles for writing internal documentation. The scope of this guide is narrow and is adapatable depending on the project and team size.
The reader is most often going to be another developer. Because of that, we can assume some level of familiarity with the code base, language/framework, or service we're writing documentation for. Consider some of the following when writing:
- Opt for explicit instructions rather than implicit. I.e. tell the reader exactly what to code. Tell them what to click in the service you're writing about.
- Provide copy and paste-able code blocks.
- Explicitly reference files that need to be updated or that stand as an example of what is being documented.
- Docs should be skimmable/scannable, so opt for descriptive headings and clear topic/introductory sentences.
- File names and topics should be easy to find by looking at file names and/or
grep
ing the docs folder.
The documentation should be consistent with the rest of the documentation in the repo. That is, it should follow a similar format (see below) and voice of other pieces of documentation. Just as we have a consistent code style within the repo, we should have a consistent documentation style within the repo.
In general, write with a neutral tone and/or the tone consistent with the documentation in the repo.
Docs can take two (of many) shapes: instructive and explanatory. Instructive docs tell a dev what to do to implement a feature, like adding a new slice to redux. Explanatory docs explain why a codebase, process, file, or function is written or how it works. Docs are often a combination of the two, but it's usually best to separate instuctions from explanations.
In the following example, we provide a few things:
- A brief overview of the feature/thing we're talking about
- Explicit step-by-step instructions for implementing/working with the thing
- An explanation of why we've opted to do it this way
- (Optional) A list of resources related to the thing if the reader is unfamiliar
# Topic
## Subtopic
Brief explanation of what subtopic is
1. Instructions
2. For implementing
3. Subtopic
Brief explanation of why we've decided to implement feature or whatever this way.
## Resources
- [Resource](link)
- [Resource](link)
- [Resource](link)
Depending on what you're documenting or the size of the codebase, a flat list of markdown files might not be the best form for documentation. Consider the following:
- Are you documenting something isolated and singular, or something that's part of a larger system? A folder might house multiple pieces of documentation about a system or a topic that has many discrete parts. An example might be a "State Management" folder with separate files for things like reducers, actions, hooks, and how the codebase tends to structure state.
- When a single file gets too long (hundreds of lines), it might be time to rethink its structure and break it into multiple files. The headings in the original file are helpful for creating the new files.
- Use relative links to link between documents.
- Use properly formatted markdown.
- Provide a semantic and skimmable hierarchy of information by using headings.
- Use lists for instructions. Numbered lists are good for sequences, whereas unordered lists are good for general tips/suggestions.
- Add a single white space between semantic elements in the markdown.
As someone who loves to write and read easily skimmable and instructional docs (especially w/ code snippet examples), those guidelines look good to me.