brettw | f0e606a5 | 2016-07-06 21:17:20 | [diff] [blame] | 1 | # Chromium coding style |
| 2 | |
| 3 | ## Main style guides |
| 4 | |
| 5 | * [Chromium C++ style guide](c++/c++.md) |
marq | 4a377b8 | 2017-02-16 18:40:19 | [diff] [blame] | 6 | * [Chromium Objective-C style guide](objective-c/objective-c.md) |
nyquist | 9d61f98 | 2017-02-10 00:29:08 | [diff] [blame] | 7 | * [Java style guide for Android](java/java.md) |
brettw | 196290a | 2016-07-07 03:52:16 | [diff] [blame] | 8 | * [GN style guide](../tools/gn/docs/style_guide.md) for build files |
brettw | f0e606a5 | 2016-07-06 21:17:20 | [diff] [blame] | 9 | |
| 10 | Chromium also uses these languages to a lesser degree: |
| 11 | |
| 12 | * [Kernel C style](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/CodingStyle?id=refs/heads/master) for ChromiumOS firmware. |
| 13 | * [IDL](https://sites.google.com/a/chromium.org/dev/blink/webidl#TOC-Style) |
| 14 | * [Jinja style guide](https://sites.google.com/a/chromium.org/dev/developers/jinja#TOC-Style) for [Jinja](https://sites.google.com/a/chromium.org/dev/developers/jinja) templates. |
| 15 | |
benwells | 3ab4165 | 2017-03-31 22:20:42 | [diff] [blame] | 16 | Regardless of the language used, please keep code [gender neutral](gender_neutral_code.md). |
| 17 | |
brettw | f0e606a5 | 2016-07-06 21:17:20 | [diff] [blame] | 18 | ## Python |
| 19 | |
thakis | 3dcdf86 | 2017-04-14 14:24:39 | [diff] [blame] | 20 | Python code should follow [PEP-8](https://www.python.org/dev/peps/pep-0008/), |
| 21 | except: |
brettw | f0e606a5 | 2016-07-06 21:17:20 | [diff] [blame] | 22 | |
| 23 | * Use two-space indentation instead of four-space indentation. |
asargent | 6b84bda8 | 2016-07-15 19:59:38 | [diff] [blame] | 24 | * Use `CamelCase()` method and function names instead of `unix_hacker_style()` names. |
| 25 | |
thakis | 3dcdf86 | 2017-04-14 14:24:39 | [diff] [blame] | 26 | (The rationale for these is mostly legacy: the code was originally written |
| 27 | following Google's internal style guideline, the cost of updating all of the |
| 28 | code to PEP-8 compliance was not small, and consistency was seen to be a |
| 29 | greater virtue than compliance.) |
| 30 | |
brettw | f0e606a5 | 2016-07-06 21:17:20 | [diff] [blame] | 31 | [Depot tools](http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools.html) |
| 32 | contains a local copy of pylint, appropriately configured. |
| 33 | |
| 34 | Note that asserts are of limited use, and should not be used for validating |
| 35 | input – throw an exception instead. Asserts can be used for validating program |
| 36 | logic, especially use of interfaces or invariants (e.g., asserting that a |
| 37 | function is only called with dictionaries that contain a certain key). [See |
| 38 | Using Assertions |
| 39 | Effectively](https://wiki.python.org/moin/UsingAssertionsEffectively). |
| 40 | |
| 41 | See also the [Chromium OS Python Style |
| 42 | Guidelines](https://sites.google.com/a/chromium.org/dev/chromium-os/python-style-guidelines). |
| 43 | |
| 44 | ## Web languages (JavaScript, HTML, CSS) |
| 45 | |
dbeam | 6c681f2 | 2017-04-20 23:37:24 | [diff] [blame] | 46 | When working on Web-based UI features, consult the [Web Development Style Guide](web/web.md) for the Chromium conventions used in JS/CSS/HTML files. |
brettw | f0e606a5 | 2016-07-06 21:17:20 | [diff] [blame] | 47 | |
| 48 | Internal uses of web languages, notably "layout" tests, should preferably follow these style guides, but it is not enforced. |