robertshield | 58e0b3f | 2017-02-14 03:55:39 | [diff] [blame] | 1 | # **Chromium Documentation Guidelines** |
| 2 | |
| 3 | Chromium's code base is large. Very large. Like most large places, it can be hard to find your way around if you don't already know the way. It also changes a lot. Lots of people work on Chromium and refactoring, componentization, addition |
Nourhan Hasan | 571a2f2 | 2024-07-26 16:50:48 | [diff] [blame] | 4 | or removal of layers, etc. means that knowledge one has can quickly get out of date. |
robertshield | 58e0b3f | 2017-02-14 03:55:39 | [diff] [blame] | 5 | |
| 6 | As a result, it can be hard to figure out how things are supposed to fit together. Documentation on [dev.chromium.org](http://dev.chromium.org/developers) can be hard to navigate and harder to keep up to date. The [starter guide](https://sites.google.com/a/chromium.org/dev/developers/how-tos/getting-around-the-chrome-source-code) is helpful, but stops at a very high-level overview. Ultimately [codesearch.chromium.org](http://codesearch.chromium.org) is the way most people explore. |
| 7 | |
| 8 | This guide attempts to lay out some practices that will make it easier for newcomers 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 documentation 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 purpose of this type of documentation is to explain what a given set of related classes 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 provide examples of usage of the class where this isn't obvious. |
| 16 | * **Implementation documentation**: This type of documentation is found next to implementations. In C++, this will tend to be embedded in .cc files. It is meant 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://codesearch.chromium.org/chromium/src/) itself. One day someone's going to come along and wonder what it's for and they'll discover that awesome-directory-name (breakpad, 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 be used and provides rough outline of the code's structure.*** |
| 25 | |
Mike Frysinger | d1630aa | 2024-07-11 01:41:24 | [diff] [blame] | 26 | The README.md file should be located at the root of the component directory and should be in [markdown format](/styleguide/markdown/markdown.md). |
robertshield | 58e0b3f | 2017-02-14 03:55:39 | [diff] [blame] | 27 | |
| 28 | The first thing in the README.md file should be a description of the component in 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 there 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 expected to be used. For components of small to moderate size (e.g. under [src/components/](https://codesearch.chromium.org/chromium/src/components/)), this can mean what 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 documentation (e.g.: [src/v8/](https://codesearch.chromium.org/chromium/src/v8/README.md)). |
| 31 | |
| 32 | The third thing should be a lay of the land of the component, sufficient breadcrumbs 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 description of the major interfaces a consumer of the component will need to care about. Again for larger components this can live in external kept-up-to-date documentation where needed. |
| 33 | |
| 34 | The fourth thing should be historical links to design docs for the component, including early ones. These are super handy for people looking to understand why the component exists in its current form. |
| 35 | |
| 36 | A great example of a README.md file is [src/native_client/README.md](https://codesearch.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 piece of code should be used. The public interface of a class or a header file containing function declarations describe the API to the code but don't necessarily say much about how it is expected to be used. As such: |
| 41 | |
Nourhan Hasan | 571a2f2 | 2024-07-26 16:50:48 | [diff] [blame] | 42 | ***Non-trivial classes or sets of function declarations in header files should include comments with a brief description of the purpose of the class or set of functions as well as examples of expected usage.*** |
robertshield | 58e0b3f | 2017-02-14 03:55:39 | [diff] [blame] | 43 | |
| 44 | (Good) examples: |
| 45 | |
| 46 | https://codesearch.chromium.org/chromium/src/base/callback_list.h |
| 47 | |
|
|