Automate code formatting to save time and sanity
I remember vividly when I had a harsh review of my code early my career.
My face was beet-red and blood was pumping.
How dare you tell me how to format my code?
May be you have been there or know somebody who did.
My case may be isolated but I have seen this scenario repeat often in code review meetings with engineers arguing endlessly about code format than the primary logic.
Later on, I was learning Python and annoyed by its opinionated indentation block syntax. However, after writing a Python program, I realized that the indentation didn’t bother me at all. I have gotten over the resistance and actually started liking it.
As programmers, we tend to be rebels and don’t appreciate to be told what to do. Code formating style becomes a contentious issue consuming productive time and at times creating personal rift between engineers.
What’s the solution then?
The clue is there in my Python experience. Once something is forced on you, preferably by a tool, you just get used to it.
The solution to this problem is fairly simple. Let a tool reformat the code automatically according to an agreed upon standard during file saving.
Remember, engineers forget about any disagreements in a few days. After that, overall team code starts looking pretty similar. With standardized formatting, engineers now concentrate more on relevant code review issues.
Prettier is an opinionated code formatting tool available for many languages. I highly recommend you to standardize on this tool and shift the focus to important things. Prettier is available as a plugin for most popular IDEs.
Since Prettier is opinioned, it defaults to a curated and well accepted formatting style. My recommendation is to start with the provided style and customize later if needed via the config file.
How about naming conventions
After formatting, there are other important aspects of writing code such as variable and function naming style such as snake case or camelCase.
Proper use of vertical space and empty lines is an important aspect for providing readable code.
These rules generally fall into linting category.
We do use CamelCase for naming things.
Main takeaway is to use Prettier or similar tool for better productivity.
Get your ProAutoma Free Account to monitor your Website or API. 50K monthly checks are free, that is 5 sites checked every 5 minutes.
Try our Free API Tester tool to explore and test your APIs. All you need is a URL to get started.