Spaces and Tabs

21 Sep 2017

With the increase in relevance of open source communities and projects involving multiple collaborators, it has become increasingly important that the code you write is legible, both to you as the author, as well as to others trying to read it. Improving legibility can be done by including documentation with your code, but the most basic tool that vastly improves your code’s legibility is adherence to a “code style”.

A code style quite literally makes your code easier to read. While the questions of using spaces versus tabs and where to indent may seem a bit trivial, code consistency is the key benefit of using a code style. By always coding in one style, you become quite adept in reading code written in that and similar styles. This is most helpful when reading code written by others, where you should be spending your time trying to understand the logic behind their code and not where they put the closing curly brace.

At first adapting to a code style is a bit of a pain. As you learn to code you develop your own style that works for you, but not necessarily your collaborators. Changing the way you code in order to facilitate others does not feel particularly useful during the typically solitary period of first learning to code. Then during more formal learning, the expected code style can vary between coursework and projects. However once you start working with others on projects, the value of a shared code style becomes apparent. All the code in the project is uniform, and reading each members’ contributions is as easy as reading your own. By following a code style, it is easier to contribute productively to a project as the other developers have to spend less time translating your code and can spend more time evaluating it and integrating it with the larger work.