The idea behind digital computers may be explained by saying that these machines are intended to carry out any operations which could be done by a human computer. Alan Turing
Code style is like the music during a dramatic scene in a movie: if you notice it then it’s a problem. Good style makes reading code a pleasurable and consistent experience. However, having to follow a style guide can feel far less than pleasurable. Think about how much there is to remember:
- Tabs vs. spaces
- Line breaking before column count
- Spaces between parentheses
- Spaces before and after braces
- Semi-colons at the end of statements
- Line breaks on chained statements
- Single quotes vs. double quotes
- Trailing commas vs. no trailing commas
Like Alan Turing said, the end goal of a computer is to do the operations of a human. If it feels dull, then a computer should do it. Manually styling your code is about as fun as working on taxes at the DMV. Automate that job!
The benefits of automating code styling go beyond making your life easier: automatic code styling can potentially reduce bugs. “That’s preposterous!”, you might say. Well, you’re right that it’s not empirically verified and this is conjecture. What is true though is that the human working memory is very limited. Just try to remember the following numbers after one read: 71828182845904523536028747135266249775724709369995957496696.
The human working memory is limited to about 7 (plus or minus 2) items. If you and your teammates have to constantly occupy working memory with style rules while writing and reviewing code, you might miss important things. Your attention is just as limited, as demonstrated by the Invisible Gorilla experiment below:
When you format your code automatically, everyone can think about the important stuff when they read your work, and you can write as sloppy as you want and the computer will make it beautiful for you automagically! There goes your case of the Mondays!
You and your team may not agree with every choice a formatter makes, and you may not even agree with the conjecture of less bugs via automatic formatting, but you’ll agree on far less if you let everyone try to follow a style guide. Code is written and reviewed by humans, we should do everything we can to limit human error. Get your team a formatter today, and don’t look back.