Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /main /. /docs /documentation_best_practices.md
blob: b8c9e954a8e86dcb33018bdd00f341e390bfb747 [file] [log] [blame] [view]
andybons3322f762015-08-24 21:37:09[diff] [blame]1# Documentation Best Practices
2
Wesley Moy32a43ba2019-04-17 02:07:30[diff] [blame]3"Say what you mean, simply and directly."-
4[BrianKernighan](http://en.wikipedia.org/wiki/The_Elements_of_Programming_Style)
andybons3322f762015-08-24 21:37:09[diff] [blame]5
6[TOC]
7
8## Minimum viable documentation
9
10A smallset of freshand accurate docsis better than a large
11assembly of"documentation"in various states of disrepair.
12
13Writeshortand useful documents.Cutout everything unnecessary,while also
14making a habit of continually massagingand improving every doc to suit your
15changing needs.**Docs work bestwhen they are alive but frequently trimmed,
16like a bonsai tree**.
17
18## Update docs with code
19
20**Change your documentationin the same CLas the code change**.This keeps your
21docs fresh,andis also a good place to explain to your reviewer what you're
22doing.
23
24## Delete dead documentation
25
26Dead docs are bad. They misinform, they slow down, they incite despair in
27new community members and laziness in existing ones. They set a precedent
28for leaving behind messes in a code base. If your home is clean, most
29guests will be clean without being asked.
30
31Just like any big cleaning project, **it's easy to be overwhelmed**.If your
32docs arein bad shape:
33
34*Take it slow, doc healthis a gradual accumulation.
35*Firstdelete what you're certain is wrong, ignore what's unclear.
36*Get the whole community involved.Devote time to quickly scan every docand
37 make a simple decision:Keepordelete?
38*Default todeleteor leave behindif migrating.Stragglers can always be
39 recovered.
40*Iterate.
41
42## Prefer the good over the perfect
43
44Documentationis an art.Thereisno perfect document, there are only proven
45methodsand prudent guidelines.See
Wesley Moy32a43ba2019-04-17 02:07:30[diff] [blame]46[Betteris better than perfect](https://github.com/google/styleguide/blob/gh-pages/docguide/philosophy.md#better-is-better-than-perfect).
andybons3322f762015-08-24 21:37:09[diff] [blame]47
48## Documentation is the story of your code
49
50Writing excellent code doesn't end when your code compiles or even if your
51test coverage reaches 100%. It's easy to write something a computer understands,
52it's much harder to write something both a human and a computer understand. Your
53mission as a Code Health-conscious engineer is to **write for humans first,
54computers second.** Documentation is an important part of this skill.
55
56There's a spectrum of engineering documentation that rangesfrom terse comments
57to detailed prose:
58
591.**Inline comments**:The primary purpose ofinline commentsis to provide
60 information that the code itself cannot contain, suchas why the codeis
61 there.
62
632.**Methodandclass comments**:
64
65***Method API documentation**:The header/Javadoc/ docstring
66 comments that say what methodsdoand how touse them.This
67 documentationis**the contract of how your code must behave**.The
68 intended audienceis future programmers who willuseand modify your
69 code.
70
71Itis often reasonable to say that any behavior documented here should
72 have a test verifying it.This documentation details what arguments the
73 method takes, what it returns, any"gotchas"or restrictions,and what
74 exceptions it canthrowor errors it canreturn.It doesnot usually
75 explain why code behaves a particular wayunless that's relevant to a
76 developer's understanding of how touse the method."Why" explanations
77 areforinline comments.Thinkin practical termswhen writing method
78 documentation:"This is a hammer. You use it to pound nails."
79
80***Class/Module API documentation**:The header/Javadoc/ docstring
81 commentsfor aclassor a whole file.This documentation gives a brief
82 overview of what theclass/ file doesand often gives a fewshort
83 examples of how you mightuse theclass/ file.
84
85Examples are particularly relevantwhen there's several distinct ways to
86 use the class (some advanced, some simple). Always list the simplest
87 use case first.
88
893. **README.md**: A good README.md orients the new user to the directory and
90 points to more detailed explanation and user guides:
91 * What is this directory intended to hold?
92 * Which files should the developer look at first? Are some files an API?
93 * Who maintains this directory and where I can learn more?
94
954. **Design docs, PRDs**: A good design doc or PRD discusses the proposed
Quinten Yearsley317532d2021-10-20 17:10:31[diff] [blame]96 implementation at length for the purpose of collecting feedback on that
andybons3322f762015-08-24 21:37:09[diff] [blame]97 design. However, once the code is implemented, design docs should serve as
98 archives of these decisions, not as half-correct docs (they are often
99 misused). See
foolipdf2a8632017-02-15 15:03:16[diff] [blame]100 [Implementation state](#Implementation-state-determines-document-repository)
andybons3322f762015-08-24 21:37:09[diff] [blame]101 below.
102
103## Implementation state determines document repository
104
105**If the doc is about implemented code, put it in README.md**. If it's
106pre-implementation discussion, includingDesign docs,PRDs,and presentations,
107keep itin sharedDrive folders.
108
109## Duplication is evil
110
111Donot write your own guide to a common technologyor process.Link to it
112instead.If the guide doesn't exist or it's badlyout of date, submit your
qyearsleyc0dc6f42016-12-02 22:13:39[diff] [blame]113updates to the appropriate docs/ directoryor create apackage-level
andybons3322f762015-08-24 21:37:09[diff] [blame]114README.md.**Take ownershipand don't be shy**: Other teams will usually welcome
115your contributions.

[8]ページ先頭

©2009-2025 Movatter.jp