Importance of Code Standards

Standards are ever present in our lives. They are the building blocks of order in an otherwise chaotic world. Software Engineering is not an exception to the rule, thusly, code standards are a basic requirement for quality systems. For companies, the quality of their digital applications represents growth, and that is something which Linio has achieved.

What are code standards?

Code standards are a series of rules defined for a programming language or a specific programming style. The style ensures that all engineers who contribute to a project have a single way to style their code, resulting in a consistent code base, making certain the product is easy to read and maintain.

The use of standards is very important in the quality of software, however, keeping all projects in perfect compliance with established standards is not an easy task. It requires great effort and consistency on the part of the engineering team. While more and more companies have adopted standards, there are still those that begin development of new projects without them.

Code standards in Linio

In the early days at Linio, we did not have an established code standard and it was common that developers wrote code in their own way, resulting in a project difficult to understand and difficult to maintain. I still remember the hours we spent finding a problem before being even close to where it might have originated due to the lack of organized code.

“Rome was not built in a day.” Linio’s migration to standard practices has been progressive, it did not happen overnight. We began to adopt standards in new projects and little by little our requirements for the changes we sent to our repositories became more meticulous. In the beginning, it became difficult to adapt, the contrast between not having rules established for the revision of code before, and the necessity of having a number of approvals in our pull requests now, was a change that not everybody took naturally, to some it took more time than others.

Nowadays, we adopt the official standards and processes of continuous integration that check our code styles. For our PHP code, we utilize php-cs-fixer to automatically format our code before trying to push them to the repository, rather than having engineers handle it by hand. There are processes to improve, but it is constant work and we are continuously working on it.

How to introduce code standards to existing projects

Not all companies use the same tools in their development and it can be complicated to find the best standards that fit with your team and codebase. But a good start to achieving quality starts with documenting the standards agreed on. We suggest creating a standards repository that your team can continuously reference, review, and update.

Considerations:

  1. Use the official standards of the tools used in each project as the base.

  2. To improve code readability, pay attention to code styles like code segments, indentation, length of lines, and line spacing.

  3. Naming variables, functions etc.

  4. Establish limits in complexity or length of functions.

And most importantly, do not stop at the application of these rules, do not increase the technical debt in the projects. Maybe today you have a very large project in which standards have never been applied and it seems a waste to start doing it, but it is a worthwhile investment to build a quality product and also an engineering team with quality. If the implementation of these standards starts to be a real headache, it is necessary to consider a complete refactoring of your system. “Divide and conquer”, it is recommended to start module by module.

Advantages of having code standards:

  1. Early error detection: When trying to comply with the standards we established, it has been easier to detect possible errors in code reviews, preventing these problems from reaching production.

  2. Reduction of complexity: Complying with the rules about code style helps build cleaner code, allowing us to easily detect opportunities to simplify our functions.

  3. Easy to read code: Respecting the standards in our projects has allowed new team members to easily adapt to the way of work and better understand the code in the repositories.

  4. Reusable code: Thanks to the use of good practices, we have code segments that can be consumed by more than one service, reducing duplicate code.

It is a good strategy to familiarize the team with the principles of clean code, below are some of the principles that inspired us to create our standards and to seek quality in our developments.

  1. DRY - Don’t Repeat Yourself.
  2. YAGNI - You Aren’t Gonna Need It.
  3. KISS - Keep It Simple, Stupid.
  4. SOLID

    S - Single-Responsibility Principle.

    O - Open-Closed Principle.

    L - Liskov Substitution Principle.

    I - Interface Segregation Principle.

    D - Dependency Inversion Principle.

Conclusion:

The implementation of standards in Linio resulted in:

  • A reduction between 60 and 80% of incidents.
  • Decrease in the number of hotfix deployments.
  • A significant improvement in the quality of the development team.

As we can see the definition and use of standards provides many benefits. Since Linio started focusing on code quality and implementing standards, I enjoy my work more than before, when there were no established rules. This has been thanks to the work of all engineers on the team, all together aiming for the same goal.

Share this: