The Importance of Coding Standards

Carlos Tasada
5 min readDec 19, 2020

Wikipedia defines standardization as “the process of implementing and developing technical standards based on the consensus of different parties that include firms, users, interest groups, standards organizations and governments”. And highlights that “Standardization can help maximize compatibility, interoperability, safety, repeatability, or quality”.

We live surrounded by standards, from the width of a road to the size of a door or the volume of a can of coke. Those standards help to make things easier. You know how many cans you can fit in a box and how many boxes you can put in a trunk. No need to be concerned about those points, they are standardized.

Standardization has a positive impact on any business, and Software Development is not an exception.

Coding Standards

Coding standards are a series of procedures, defined for a particular programming language, specifying a programming style.

A coding standard makes sure that all the developers working on the project are following certain specified guidelines. The code can be easily understood and proper consistency is maintained.

Coding standards are agreed-with guides of the best-practices that developers have decided to follow when writing code for a project.

If you Google for coding standards you will find many of them, varying by the programming language and other paradigms the teams behind them decided to follow.

Why are coding standards important?

Your code is easier to read

When you use a standard, your code is readable, both to you and others. The reason is that now it’s consistent.

The ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code. Therefore, making it easy to read makes it easier to write.
Robert C. Martin, Clean Code: A Handbook for Agile Software Craftsmanship

Your code is easier to understand

This is one of the most important points. We need to make sure the code can be understood by any developer, either you or a colleague, now or in the future.

Having properly defined rules about the naming conventions, the tabulation or how to structure your code files, the intent of your code needs to be easily understood.

Your code is easier to maintain

If the code is easier to read and understand, adding new features or fixing bugs is now much easier.

Your code is easier to collaborate on

Imagine an orchestra, and every musician playing the same song, but at different times or different tunes. It would be chaos, no matter how well each of them played individually.

In large projects, with dozens or even hundreds of developers collaborating, having common standards help to keep the code clean and allow for multiple developers to collaborate and feel familiar with the code base.

Your code is more secure

Poor coding practices may expose your software to security vulnerabilities.

Coding standards are more than camelCase vs snail_case. Coding standards also indicate how to expose the methods of your class or how to query a database or external service. Knowing those guidelines will help you to create more secure software.

Your code is more performant

Even if it is good code, not following the standard may have an adverse effect on the performance of your software.

Language interpreters are becoming better and better at understanding the code, but there are still multiple multiple areas where good coding standards can be beneficial.

Executing the cheaper code at the beginning of a comparison, using specific libraries for some needs (connections, date formatting, etc) or when to use threads or instantiate a class, can have a huge performance impact on your software.

What makes a good code standard?

We already mentioned it earlier, but let’s repeat it:

Coding standards are agreed-with guides of the best-practices that developers have decided to follow when writing code for a project.

One of the main reasons there are so many coding standards it’s because there’s no silver bullet, anyway there are a few points that should be always considered:

Define a coding standard per programming language

If your organization uses multiple programming languages, don’t try to reuse your coding standard. Each programming language has its own paradigms, and it’s much easier to respect them and design accordingly. Of course, that doesn’t mean that you cannot reuse parts of it. Security practices and some design principles can, and probably should be shared.

Base your coding standard in best-practices and proved standards

The whole idea of making your code easier to read, understand and maintain falls down if your coding standards are weird. Big companies such as Google or Uber or frameworks like Symfony or Spring have well established code style guidelines, so try to use the one that is closest to your needs, maybe based on programming language or framework, and expand it if needed.

Basing your coding standards in some of those existing guidelines will not only give you a good starting point, but also will make it easier for your developers to adopt them, since they are probably already familiar with them.

“The Yoga Rule”™

The coding standards must be encouraged and even enforced to guarantee that you collect their benefits. Aside from sharing them in a clear way, you can also use tooling to help your developers to quickly identify deviations from the rules. Tools like CheckStyle, PHPStan or ESLint can help validating that your code follows the expected rules.

Software development is probably the most fast pacing engineering. New technologies and trends appear at speeds that cannot be compared with other disciplines. This is an important fact to keep in mind while working with coding standards.

Yoga is a group of physical, mental and spiritual practices, which help develop flexibility, strength and balance.

As in Yoga, your coding standards must be:

  • Strong: The coding standards must be enforced and applied.
  • Flexible: The coding standards need to be flexible. They need to evolve when needed and accept that there will be corner cases where they cannot be applied.
  • Balanced: The coding standards need to be balanced. They need to help increase the code quality, development speed, security and performance. From time to time we will need to compromise.

Nothing is written in stone

As we just saw in “The Yoga Rule”™ the coding standards need to be flexible, they are, in fact, live entities. As such, it’s perfectly normal that a newly created coding standard requires multiple iterations at the beginning, while rules and scenarios are tweaked and improved. At some point it will be considered stable, until news trends, technologies or other external factors force you to start changing your guidelines again.

So please, do your homework, find, define or expand the standard that works best for you, your team and organization, and adhere to it.

Happy finding your code standard and success in your coding experience!

--

--

Carlos Tasada

Seasoned developer with passion for scalability, architecture and professional growth