Skip to content

Commit edccafa

Browse files
committed
Google Documentation Guide
Includes Markdown Style Guide See docguide/README.md
1 parent 43d738a commit edccafa

File tree

6 files changed

+686
-0
lines changed

6 files changed

+686
-0
lines changed

docguide/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Google documentation guide
2+
3+
* [Markdown styleguide](style.md)
4+
* [Best practices](best_practices.md)
5+
* [README files](READMEs.md)
6+
* [Philosophy](philosophy.md)
7+
8+
## See also
9+
10+
* [How to update this guide](https://goto.google.com/doc-guide), for Googlers.

docguide/READMEs.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# README.md files
2+
3+
About README.md files.
4+
5+
1. [Overview](#overview)
6+
1. [Guidelines](#guidelines)
7+
1. [Filename](#filename)
8+
1. [Contents](#contents)
9+
1. [Example](#example)
10+
11+
## Overview
12+
13+
`README.md` files are Markdown files that describe a directory.
14+
GitHub and Gitiles renders it when you browse the directory.
15+
16+
For example, the file /README.md is rendered when you view the contents of the
17+
containing directory:
18+
19+
https://github.com/google/styleguide/tree/gh-pages
20+
21+
Also `README.md` at `HEAD` ref is rendered by Gitiles when displaying repository
22+
index:
23+
24+
https://gerrit.googlesource.com/gitiles/
25+
26+
## Guidelines
27+
28+
**`README.md` files are intended to provide orientation for engineers browsing
29+
your code, especially first-time users.** The `README.md` is likely the first
30+
file a reader encounters when they browse a directory that
31+
contains your code. In this way, it acts as a landing page for the directory.
32+
33+
We recommend that top-level directories for your code have an up-to-date
34+
`README.md` file. This is especially important for package directories that
35+
provide interfaces for other teams.
36+
37+
### Filename
38+
39+
Use `README.md`.
40+
41+
Files named `README` are not displayed in the directory view in Gitiles.
42+
43+
### Contents
44+
45+
At minimum, every package-level `README.md` should include or point to the
46+
following information:
47+
48+
1. **What** is in this package/library and what's it used for.
49+
2. **Who** to contact.
50+
3. **Status**: whether this package/library is deprecated, or not for general
51+
release, etc.
52+
4. **More info**: where to go for more detailed documentation, such as:
53+
* An overview.md file for more detailed conceptual information.
54+
* Any API documentation for using this package/library.
55+
56+
## Example
57+
58+
```markdown
59+
# APIs
60+
61+
This is the top-level directory for all externally-visible APIs, plus some
62+
private APIs under `internal/` directories.
63+
See [API Style Guide](docs/apistyle.md) for more information.
64+
65+
*TL;DR*: API definitions and configurations should be defined in `.proto` files,
66+
checked into `apis/`.
67+
68+
...
69+
```

docguide/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0

docguide/best_practices.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Documentation Best Practices
2+
3+
"Say what you mean, simply and directly." - [Brian Kernighan]
4+
(http://en.wikipedia.org/wiki/The_Elements_of_Programming_Style)
5+
6+
Contents:
7+
8+
1. [Minimum viable documentation](#minimum-viable-documentation)
9+
1. [Update docs with code](#update-docs-with-code)
10+
1. [Delete dead documentation](#delete-dead-documentation)
11+
1. [Documentation is the story of your code](#documentation-is-the-story-of-your-code)
12+
13+
## Minimum viable documentation
14+
15+
A small set of fresh and accurate docs are better than a sprawling, loose
16+
assembly of "documentation" in various states of disrepair.
17+
18+
Write short and useful documents. Cut out everything unnecessary, while also
19+
making a habit of continually massaging and improving every doc to suit your
20+
changing needs. **Docs work best when they are alive but frequently trimmed,
21+
like a bonsai tree**.
22+
23+
This guide encourages engineers to take ownership of their docs and keep
24+
them up to date with the same zeal we keep our tests in good order. Strive for
25+
this.
26+
27+
* Identify what you really need: release docs, API docs, testing guidelines.
28+
* Delete cruft frequently and in small batches.
29+
30+
## Update docs with code
31+
32+
**Change your documentation in the same CL as the code change**. This keeps your
33+
docs fresh, and is also a good place to explain to your reviewer what you're
34+
doing.
35+
36+
A good reviewer can at least insist that docstrings, header files, README.md
37+
files, and any other docs get updated alongside the CL.
38+
39+
## Delete dead documentation
40+
41+
Dead docs are bad. They misinform, they slow down, they incite despair in
42+
engineers and laziness in team leads. They set a precedent for leaving behind
43+
messes in a code base. If your home is clean, most guests will be clean without
44+
being asked.
45+
46+
Just like any big cleaning project, **it's easy to be overwhelmed**. If your
47+
docs are in bad shape:
48+
49+
* Take it slow, doc health is a gradual accumulation.
50+
* First delete what you're certain is wrong, ignore what's unclear.
51+
* Get your whole team involved. Devote time to quickly scan every doc and make
52+
a simple decision: Keep or delete?
53+
* Default to delete or leave behind if migrating. Stragglers can always be
54+
recovered.
55+
* Iterate.
56+
57+
## Prefer the good over the perfect
58+
59+
Your documentation should be as good as possible within a reasonable time frame.
60+
The standards for an documentation review are different from the
61+
standards for code reviews. Reviewers can and should ask for improvements, but
62+
in general, the author should always be able to invoke the "Good Over Perfect
63+
Rule". It's preferable to allow authors to quickly submit changes that improve
64+
the document, instead of forcing rounds of review until it's "perfect". Docs are
65+
never perfect, and tend to gradually improve as the team learns what they really
66+
need to write down.
67+
68+
## Documentation is the story of your code
69+
70+
Writing excellent code doesn't end when your code compiles or even if your
71+
test coverage reaches 100%. It's easy to write something a computer understands,
72+
it's much harder to write something both a human and a computer understand. Your
73+
mission as a Code Health-conscious engineer is to **write for humans first,
74+
computers second.** Documentation is an important part of this skill.
75+
76+
There's a spectrum of engineering documentation that ranges from terse comments
77+
to detailed prose:
78+
79+
1. **Inline comments**: The primary purpose of inline comments is to provide
80+
information that the code itself cannot contain, such as why the code is
81+
there.
82+
83+
2. **Method and class comments**:
84+
85+
* **Method API documentation**: The header / Javadoc / docstring
86+
comments that say what methods do and how to use them. This
87+
documentation is **the contract of how your code must behave**. The
88+
intended audience is future programmers who will use and modify your
89+
code.
90+
91+
It is often reasonable to say that any behavior documented here should
92+
have a test verifying it. This documentation details what arguments the
93+
method takes, what it returns, any "gotchas" or restrictions, and what
94+
exceptions it can throw or errors it can return. It does not usually
95+
explain why code behaves a particular way unless that's relevant to a
96+
developer's understanding of how to use the method. "Why" explanations
97+
are for inline comments. Think in practical terms when writing method
98+
documentation: "This is a hammer. You use it to pound nails."
99+
100+
* **Class / Module API documentation**: The header / Javadoc / docstring
101+
comments for a class or a whole file. This documentation gives a brief
102+
overview of what the class / file does and often gives a few short
103+
examples of how you might use the class / file.
104+
105+
Examples are particularly relevant when there's several distinct ways to
106+
use the class (some advanced, some simple). Always list the simplest
107+
use case first.
108+
109+
3. **README.md**: A good README.md orients the new user to the directory and
110+
points to more detailed explanation and user guides:
111+
* What is this directory intended to hold?
112+
* Which files should the developer look at first? Are some files an API?
113+
* Who maintains this directory and where I can learn more?
114+
115+
See the [README.md guidelines](READMEs.md).

docguide/philosophy.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Philosophy
2+
3+
埏埴以為器,當其無,有器之用.
4+
5+
*Clay becomes pottery through craft, but it's the emptiness that makes a pot
6+
useful.*
7+
8+
\- [Laozi](http://ctext.org/dictionary.pl?if=en&id=11602)
9+
10+
Contents:
11+
12+
1. [Radical simplicity](#radical-simplicity)
13+
1. [Readable source text](#readable-source-text)
14+
1. [Minimum viable documentation](#minimum-viable-documentation)
15+
1. [Better is better than perfect](#better-is-better-than-perfect)
16+
17+
## Radical simplicity
18+
19+
* **Scalability and interoperability** are more important than a menagerie of
20+
unessential features. Scale comes from simplicity, speed, and ease.
21+
Interoperability comes from unadorned, digestable content.
22+
23+
* **Fewer distractions** make for better writing and more productive reading.
24+
25+
* **New features should never interfere with the simplest use case** and should
26+
remain invisible to users who don't need them.
27+
28+
* **This guide is designed for the average engineer** -- the busy,
29+
just-want-to-go-back-to-coding engineer. Large and complex documentation is
30+
possible but not the primary focus.
31+
32+
* **Minimizing context switching makes people happier.** Engineers should be
33+
able to interact with documentation using the same tools they use to read and
34+
write code.
35+
36+
## Readable source text
37+
38+
* **Plain text not only suffices, it is superior**. Markdown itself is not
39+
essential to this formula, but it is the best and most widely supported
40+
solution right now. HTML is generally not encouraged.
41+
42+
* **Content and presentation should not mingle**. It should always be possible
43+
to ditch the renderer and read the essential information at source. Users
44+
should never have to touch the presentation layer if they don't want to.
45+
46+
* **Portability and future-proofing leave room for the unimagined integrations
47+
to come**, and are best achieved by keeping the source as human-readable as
48+
possible.
49+
50+
* **Static content is better than dynamic**, because content should not depend
51+
on the features of any one server. However, **fresh is better than stale**. We
52+
strive to balance these needs.
53+
54+
## Minimum viable documentation
55+
56+
* **Docs thrive when they're treated like tests**: a necessary chore one learns
57+
to savor because it rewards over time.
58+
See [Best Practices](best_practices.md).
59+
60+
* **Brief and utilitarian is better than long and exhaustive**. The vast
61+
majority of users need only a small fraction of the author's total knowledge,
62+
but they need it quickly and often.
63+
64+
## Better is better than perfect
65+
66+
* **Incremental improvement is better than prolonged debate**. Patience and
67+
tolerance of imperfection allow projects to evolve organically.
68+
69+
* **Don't lick the cookie, pass the plate**. We're drowning in potentially
70+
impactful projects. Choose only those you can really handle and release those
71+
you can't.

0 commit comments

Comments
 (0)