Code style
Why consistency matters
I’m a big proponent of enforcing code style, with an editor plugin and with build server checks. This way no bad code can slip through to the codebase.
But it’s not because I like specific code style. Aesthetics doesn’t matter. I don’t really care if you will use quotes or double quotes. Camel case or snake case. Those details are irrelevant. They do not matter for the end user, so stop worry about which code style is the best.
Consistency is the key.
Saying all that there are less readable choices. Those are out. The reason being that they hinder the job of a programmer and everything which does that should be avoided.
With code, I spend the most time reading it. Find where the change needs to happen. Understand the piece you are looking at. This happens all the time.
Having consistent style means I can do my task faster. I can scan given method and know what to expect. My eye will learn graphical patterns. Given set of characters will immediately transfer its meaning. You become more precise and faster.
On the other hand, without consistent styling, each time I encounter a piece of code first task is to adjust to the local flavor. Only then I can start decoding the meaning behind it. Granted, it doesn’t take long, but given that it’s the most common tasks while programming I want to avoid what’s unnecessary. Because it happens so often any moment lost while reading will compound to a lot of lost time.
I like to think about consistent styling as having consistent formatting for a book.
Imagine reading a book where each sentence or each page would look differently. You would have one page completely bold. Another one with margins so huge that you would have only one word per line. And yet another one would have line height set so low that the lines would jumble together. It would be harder to read, unnecessary harder.
We should treat our code in the same way as a published text. The consistency makes it easier to focus on the content, on the message, on the underlying meaning. It makes reading it easier and that means we can get our job faster.