Code Health Explained

Introduction 

With evolving technology, products are becoming more complex. Now, large numbers of people work on single product from different time zones. With this, the importance of having code that is easily understood and maintainable by others has become paramount. In general, this is called code health.

At a basic level, code health is about how easily software can be modified to correct faults, improve performance, or add new capabilities. If code health of a product is low, it takes more effort for developer to code with both confidence and efficiency. Trying to parse a codebase with low-code health is difficult enough for experienced developers, but it’s almost impossible for new developers. High code health is good for quality product as well as for team effectiveness.

There are few attributes that can contribute to Code Health of product…

  • Simplicity: Writing a code that is easy to understand. The practices that could be used here are use of design patterns, using basic concepts, function parameters and size etc.
  • Readability: How easy it is easy to read code i.e. sentence structure. With industry moving towards open source, this is very important. The practices that could be used here is deigning code guidelines, writing descriptive code etc.…
  • Testability: An important attribute because this is the only way that developer can be confirm if changes made are working as expected or not. if software is not developed with testability in mind, it generally results in software that is more difficult to test hence impact quality. The practices that can be used here is to design an product that can be automated. This is very important in in the era of Agile and CI.
  • Buildability: This is the ecosystem/environment that the developer uses to get feedback on written code. This is needed to maintain effective code over a period time. It is very rare that once code is written isn't modified in the future.

Above are the points that should be considered while designing any product. But what actions must to be taken to achieve code health? To achieve this, experts suggest:

  • Shared Learning: There should be an open inter/intra communication with in various organization groups for writing best code so that everybody is on same page.
  • Community: There should be community at group/organization level who monitors the coding practices being used, designs guidelines and conduct sessions to improve code health.
  • Tools: Tools should be designed at group/organization level to improve code health, like a tool that automatically deletes unused code, does formatting etc.…

Saying whether product code is healthy or not is very subjective topic. What are the metrics that should be considered while deciding code health? Here are few…

  • CHURN: A measure how many times file has changed over a specific amount of time or in whole life of product. If a file has been changed frequently there is high probability to change in future as well. This affects code health.
  • CODE COVERAGE: A measure of how much product code is executed when tests are run. A code that can be tested fully is healthy code because after modifications, issues can be detected faster.
  • COMPLEXITY: A measure of how much effort is required to understand/modify a piece of code. The more complex code is, the riskier it is to change.