Some people view certain code quality practices, especially code formatting standards, as very nit-picky things to enforce. Somehow, these always seem to only apply to the practices that we don’t agree with though. It’s not nit-picky to require braces on a new line, but it is to require spaces instead of tabs.
Why do we even try to enforce these things if people push back so hard against them? Is a consistent formatting really worth the seemingly constant battle to keep such a practice? It seems that just by the very fact that we still discuss this, and we do still have code formatting standards suggests that this is something that is worth-while.
Developers are constantly worried about cognitive load. We always talk about it. We all know that we cannot always keep an entire system’s processes, or models, or database, in our heads all at once. We are constantly looking for ways to lower that cognitive load, so that we can still work effectively, while having less stuff in our heads (this is one of the big benefits to microservices — theoretically you need only concern yourself with this one small head-sized service). Maintaining a consistent code formatting practice is one way to help reduce that cognitive load. Other coding best practices may also help with this, if nothing else simply to make writing “correct” code easier.
If you can go anywhere within a code base, and the code all looks the same, there is less information you have to process. The more a code base is inconsistently formatted, the more you have to work at reading the code, which likely means you are pushing some other valuable piece of information out of your head to make room for the “new stuff”. When a code base is consistent, after you spend a long enough time in it, reading the code will come naturally. When we read normal human language in our native language, we rarely have to push things out of the way to “make room” for what we are reading. A good code formatting practice can act like that native language. And when that practice is broken, it can be as disruptive as suddenly turning the page to find a foreign language in a book; even if you understand the language, you have to make the switch from processing one way to processing a different way.
Originally Posted on my Blogger site August of 2017