Everyone has their own style of writing and speaking. The words we choose combined with the syntax of our sentences communicate what we wish to express. The same idea applies to writing code. Programmers naturally have their own preferences when it comes to specific situations such as deciding how much indentation to add on a new line, naming variables, and determining where to place your opening and closing brackets in functions. Each programmer’s style is determined by the combination of these conventions.
Recently, I started using IntelliJ as my IDE for Javascript with ESLint included to keep the syntax of the code consistent. It was a bit frustrating at first as I had to conform my style to meet the benchmarks of ESLint. I would often get errors for simple “mistakes” such as not adding a space before an opening or closing bracket and adding unnecessary spaces. At times, it became very tedious to attend to every little detail just to remove the squiggly red lines in the code.
However, I will admit that it has saved me from critical errors in my code. On a few occasions, I misplaced a bracket, added one too many, or misspelled a variable. ESLint gave me a red flag and explained what the problem was so I could fix it.
In the past, there have been times where I used an IDE without coding standards. I remember spending hours looking through code just to find out that errors in my code were due to issues that could have been caught if I had coding standards implemented. Some of the problems I had included misplaced brackets and misspelled variables. Doesn’t that sound familiar?
New coding standards can be tedious to follow, especially for programmers that have been writing code for years. At times you may even wonder, “why bother?”
The importance of coding standards is highlighted when working in teams. Having a consistent style throughout the code can make debugging problems easier. Consistency also makes it easier for the team to understand what a block of code means. Conversely, writing in many different styles may cause a programmer to be confused when they see a function being called in a different ways.
I personally believe that coding standards are great to keep the code consistent. I’d rather have to add an extra space here and there than spend hours looking for the lost bracket in hundreds of lines of code.
The key to consistency is a good coding standard.