Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A coding style is a set of conventions on how to format code. For instance, what do you call your variables? Do you use spaces or tabs for indentation? Where do you put comments? Consistently using the same style throughout your code makes it easier to read. Code that is easy to read is easier to understand by you as well as by potential collaborators. Therefore, adhering to a coding style reduces the risk of mistakes and makes it easier to work together on software. Why Coding Style Matters is a nice article on why coding styles matter and how they increase software quality.

A lint roller cleaning up code, symbolizing the transformation of messy, disorganised information into a clean and readable format.

Figure 1:The Turing Way project illustration by Scriberia. Used under a CC-BY 4.0 licence. DOI: The Turing Way Community & Scriberia (2024).

Style Guides

Style guidelines differ between organisations, languages, and over time. Even the Python style guide Python Enhancement Proposal 8 (PEP 8) has had numerous revisions since it was released in 2001. You must choose a framework that is best for your purposes: be they for your benefit or the benefit of others. It is also important to remain consistent (and not consistently inconsistent)!

For example, PEP8 is the most widely used Python coding style and ECMAScript 6 aka ES6 is the scripting-language specification standardized by ECMA International for programming in Javascript.

For commonly used style guides for various programming languages see the Language Guides. Google also has a style guide for many languages that are used in open source projects originating out of Google.

Here are links to existing style guides for various languages:

The Zen of Python, by Tim Peters. Listing all aphorisms for coding design in Python.

Figure 2:Point 7 of the Zen of Python is “Readability Counts”. (This can be printed with the python command >>> import this)

References
  1. The Turing Way Community, & Scriberia. (2024). Illustrations from The Turing Way: Shared under CC-BY 4.0 for reuse. Zenodo. 10.5281/ZENODO.13882307