blob: 1a24bb5e957fa7908e5b3efdfcdc431b4f46ae8a [file] [log] [blame] [view]
brettwf0e606a52016-07-06 21:17:201# Chromium coding style
2
3## Main style guides
4
5 * [Chromium C++ style guide](c++/c++.md)
marq4a377b82017-02-16 18:40:196 * [Chromium Objective-C style guide](objective-c/objective-c.md)
nyquist9d61f982017-02-10 00:29:087 * [Java style guide for Android](java/java.md)
brettw196290a2016-07-07 03:52:168 * [GN style guide](../tools/gn/docs/style_guide.md) for build files
brettwf0e606a52016-07-06 21:17:209
10Chromium 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
benwells3ab41652017-03-31 22:20:4216Regardless of the language used, please keep code [gender neutral](gender_neutral_code.md).
17
brettwf0e606a52016-07-06 21:17:2018## Python
19
thakis3dcdf862017-04-14 14:24:3920Python code should follow [PEP-8](https://www.python.org/dev/peps/pep-0008/),
21except:
brettwf0e606a52016-07-06 21:17:2022
23 * Use two-space indentation instead of four-space indentation.
asargent6b84bda82016-07-15 19:59:3824 * Use `CamelCase()` method and function names instead of `unix_hacker_style()` names.
25
thakis3dcdf862017-04-14 14:24:3926(The rationale for these is mostly legacy: the code was originally written
27following Google's internal style guideline, the cost of updating all of the
28code to PEP-8 compliance was not small, and consistency was seen to be a
29greater virtue than compliance.)
30
brettwf0e606a52016-07-06 21:17:2031[Depot tools](http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools.html)
32contains a local copy of pylint, appropriately configured.
33
34Note that asserts are of limited use, and should not be used for validating
35input – throw an exception instead. Asserts can be used for validating program
36logic, especially use of interfaces or invariants (e.g., asserting that a
37function is only called with dictionaries that contain a certain key). [See
38Using Assertions
39Effectively](https://wiki.python.org/moin/UsingAssertionsEffectively).
40
41See also the [Chromium OS Python Style
42Guidelines](https://sites.google.com/a/chromium.org/dev/chromium-os/python-style-guidelines).
43
44## Web languages (JavaScript, HTML, CSS)
45
dbeam6c681f22017-04-20 23:37:2446When 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.
brettwf0e606a52016-07-06 21:17:2047
48Internal uses of web languages, notably "layout" tests, should preferably follow these style guides, but it is not enforced.