Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: docs/documentation_guidelines.md

Issue 2691203002: Add Chromium documentation guidelines. (Closed)
Patch Set: Remove unneeded line breaks. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # **Chromium Documentation Guidelines**
2
3 Chromium's code base is large. Very large. Like most large places, it can be har d to find your way around if you don't already know the way. It also changes a l ot. Lots of people work on Chromium and refactoring, componentization, addition
4 or removal of layers, etc. means that knowledge one does have can quickly get ou t of date.
5
6 As a result, it can be hard to figure out how things are supposed to fit togethe r. Documentation on [dev.chromium.org](http://dev.chromium.org/developers) can b e hard to navigate and harder to keep up to date. The [starter guide](https://si tes.google.com/a/chromium.org/dev/developers/how-tos/getting-around-the-chrome-s ource-code) is helpful, but stops at a very high-level overview. Ultimately [cod esearch.chromium.org](http://codesearch.chromium.org) is the way most people exp lore.
7
8 This guide attempts to lay out some practices that will make it easier for newco mers to find their way around Chromium's code and for old hands to keep up with a constantly evolving code base. It works from the principle that all documentat ion is wrong and out of date, but in-code documentation is less so and valuable.
9
10 ## Guidelines
11
12 In-code documentation can be categorized into three tiers:
13
14 * **Module / component documentation**: This is documentation that tends to be found in README.md files at the root level directory of a component. The purpos e of this type of documentation is to explain what a given set of related classe s are for, roughly how they are structured and *what* the component is expected to be used for.
15 * **Interface / class documentation**: This is documentation most often found in header files near class definitions. This may describe what a class or small set of classes are for and *how* they are intended to be used. It may also provi de examples of usage of the class where this isn't obvious.
16 * **Implementation documentation**: This type of documentation is found next t o implementations. In C++, this will tend to be embedded in .cc files. It is mea nt to help a reader understand *how the code works* or explain an implementation path that might not be obvious from the code itself.
17
18 Let's dig in a bit to how to use these types of documentation in Chromium.
19
20 ### Module / component documentation
21
22 Ok, so you're working on something big and important. Maybe it's a chunk of code that merits living in its own component in [src/components/](https://codesearch .chromium.org/chromium/src/components/) or even directly under [src/](https://co desearch.chromium.org/chromium/src/) itself. One day someone's going to come alo ng and wonder what it's for and they'll discover that awesome-directory-name (br eakpad, courgette, mojo, rutabaga, quick: which one of those was made up?) doesn 't by itself shed a lot of light on what the code does.
23
24 ***Any self contained unit of code that merits a container directory should have a README.md file that describes what that component is, how it is expected to b e used and provides rough outline of the code's structure.***
25
26 The README.md file should be located at the root of the component directory and should be in [markdown format](https://www.chromium.org/developers/markdown-docu mentation) according to the markdown [style guide](https://github.com/google/sty leguide/blob/gh-pages/docguide/style.md).
27
28 The first thing in the README.md file should be a description of the component i n sufficient detail that someone unfamiliar with the code will understand why it exists. It should answer the questions "what does this component do?" and "is t here any in particular I should know about it?". Some larger components (e.g. v8 , mojo, etc.) may have additional up-to-date documentation on [dev.chromium.org] (http://dev.chromium.org) or elsewhere makes sense too.
29
30 The second thing in the README.md file should be an outline of how it is expecte d to be used. For components of small to moderate size (e.g. under [src/componen ts/](https://codesearch.chromium.org/chromium/src/components/)), this can mean w hat are the main classes to care about. For larger components this can describe how to go about using the component, possibly in the form of links to external d ocumentation (e.g.: [src/v8/](https://codesearch.chromium.org/chromium/src/v8/RE ADME.md)).
31
32 The third thing should be a lay of the land of the component, sufficient breadcr umbs for a newcomer to be able to orient themselves. This usually means at least an explanation of the subdirectories of the component and possibly a descriptio n of the major interfaces a consumer of the component will need to care about. A gain for larger components this can live in external kept-up-to-date documentati on where needed.
33
34 The fourth thing should be historical links to design docs for the component, in cluding early ones. These are super handy for people looking to understand why t he component exists in its current form.
35
36 A great example of a README.md file is [src/native_client/README.md](https://cod esearch.chromium.org/chromium/src/native_client/README.md). There are many more examples that are waiting to be made great.
37
38 ### Interface / class documentation
39
40 Class and function declarations in header files describe to the world how a piec e of code should be used. The public interface of a class or a header file conta ining function declarations describe the API to the code but don't necessarily s ay much about how it is expected to be used. As such:
41
42 ***Non-trivial classes or sets of function declarations in header files should i nclude comments with a brief description of the purpose of the class or set of f unctions as well as examples of expected usage. ***
43
44 (Good) examples:
45
46 https://codesearch.chromium.org/chromium/src/base/callback_list.h
47
48 https://codesearch.chromium.org/chromium/src/base/feature_list.h
49
50 ### Implementation documentation
51
52 Code should be as self documenting as possible, but sometimes that isn't enough. Maybe there's a tricky bit of implementation that isn't obvious. Maybe there's a clever algorithm that has a good reason it needs to be clever. A good rule of thumb is that if a code reviewer had a clarifying question about something durin g review and the code couldn't be simplified to answer the question then a comme nt is probably appropriate. Don't go nuts here though, often if code is so compl icated that it needs lots of comments, then it could probably be simplified firs t.
53
54 ## Language
55
56 Be concise.
57
58 Use correct grammar as much as possible.
59
60 Avoid fancy or confusing language.
61
62 Don't assume that readers know everything you currently know.
63
64 ## Working with existing code
65
66 If you got this far and have some experience with Chromium's code, you'll have f igured out that these guidelines are aspirational more than what the world looks like today. So what do we do when working with existing code.
67
68 First off: ***[Documentation changes can be TBRed](https://chromium.googlesource .com/chromium/src/+/master/docs/code_reviews.md#TBR_ing-documentation-updates)** *. Even in-code changes. If you have discovered something that isn't documented, have figured out how it works and would like to pay it forward, feel free to wr ite something down and check it in.
69
70 At the component level, if you are the owner of a component that isn't documente d, please add a README.md with content as per the above.
71
72 If you don't own a component and figure out how it works, consider adding some n otes to the component's README.md file. You don't need to be an expert to share what you do know with those who come afterwards.
73
74 The same applies to class level comments and implementation comments. If you fin d yourself modifying code and realizing that it is… under-documented.. feel free to add some notes nearby.
75
76 In general, use your judgment. Changes will NOT be blocked on requiring people t o add missing documentation, but adding missing docs is a great way to make our code base healthier.
77
78 ## FAQ
79
80 #### Are these hard rules?
81
82 [Well, no](https://www.youtube.com/watch?v=jl0hMfqNQ-g). This said, following th ese guidelines will make our code base healthier, more consistent and much easie r to understand. Over time improving in-code documentation will make the whole t eam faster. But if a small fix is genuinely needed (it almost always isn't), the n don't block on writing detailed documentation. As always: use your judgment.
83
84 #### I'm not an expert on this undocumented code, should I still add documentati on?
85
86 Yes! Partial documentation is much better than no documentation.
87
88 #### I hate writing documentation, it will slow me down!
89
90 Chromium is big enough and complicated enough that a newcomer has to read a lot of code to figure out how things fit together. Documentation provides breadcrumb s to speed up understanding, which over time will make the whole team work more quickly. Short term execution speed is far less important than long term team ve locity.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698