4 ms·
The point is not that any one code formatting style is best, the point is that consistency in formatting across a codebase helps you read code faster. Our eyes
by yashap 5y ago
The point is not that any one code formatting style is best, the point is that consistency in formatting across a codebase helps you read code faster. Our eyes and brains are good at picking up patterns - consistent patterns lets our brains parse code faster than if every file is written in a different style.
Furthermore, not worrying at all about indentation, spacing, brace placement, semicolons or not, etc. lets me write code faster, not just read it faster. Type it out with zero effort expended on formatting, save, editor auto-formats.
It’s not that any of this saves crazy amounts of time, but it does make all of code writing, code reading and code reviews slightly faster. When it’s so easy to setup, why not do it?
The only argument I can see against auto-formatters is that people like to put their own artistic touch on the code they write. I get that, but it wastes time, especially when everyone starts doing things in their own style.
I’ve been working professionally as a dev for 9 years, also on teams that use auto-formatters, and teams that don’t. I think they’re a small but clear productivity booster. The only time I’d consider not using one is in languages where the formatter itself is super slow. But fast ones, where you can setup nearly instantaneous “format on save” (go fmt, prettier, etc.), no brainer.