Coding style guides¶
A style guide defines rules and guidelines for how to structure and format your code. This can make code easier to write, because you don't need to worry about how to format your code. It can also make code easier to read, because consistent styling allows you to focus on the content.
There are two types of tools that can help you use a style guide:
-
A formatter formats your code to make it consistent with a specific style; and
-
A linter checks whether your code is consistent with a specific style.
Recommended style guides¶
Because programming languages can be very different from each other, style guides are usually defined for a single programming language.
Here we list some of the most widely-used style guides for several common programming languages:
- For R there is a tidyverse style guide.
- You can apply this style to your code with styler.
-
You can check that your code conforms to this style with lintr.
-
For Python there is Black, which defines a coding style and applies this style to your code.
-
For C++ there is a Google C++ style guide.