Importance Of Coding Standards

This post has already been published on code::gallery blog which now has been merged into this blog.

Dr. Dobb’s Portal has an article on code quality improvement via coding standards conformance. The concept of coding standards is considered a part of development best practices but the way it is implemented is a pet subject for controversy. In some cases improper coding standards policies have been known to be harmful or less productive.


The purpose of implementing a coding standard is to make the code homogeneous throughout the project so that is more maintainable. If it was that once written the code is never looked into, the value of coding standards would diminish. However, the reality is that code has bugs, which might be solved by others, a software evolves through its entire product cycle which leads to evolution and reuse of code on existing base. If the code is presented with consistency, it is easier to read and understand it, even by someone else.

This means that coding standard is not only about naming conventions. It should define how a block of code should look like, it should define indentation and policies to avoid generation of complex code like using multiple or nested ifs or incomprehensible loops. e.g., switch/select-case instead of a huge block of if-else if-else might be useful in languages like C++ and Java. Today all the higher languages support multiple constructs for flow control.

For Whom?

Ideally coding standards should be used by everyone in every project. However, its perceptible value might change depending on the size and the skill set. Even in a one-man project, coding standards help in keeping it clean over a longer period of time, but in larger projects they are a must. It is a requirement today to have people of varying skills in a project. Coding standards keep everyone on the same page and make the code comprehensible to everyone.

Coding standards become of prime importance for an open and distributed team. A lot of open source projects accept contributions from volunteers and users, the project will become a disaster if coding standards are not enforced. A good example is coding conventions put forth by Velocity.

The Problem

There are two main reasons why coding standards are opposed to:

  • Clash with personal style: A lot of engineers develop their own style of programming, which might be best for themselves. However, in a team it might not be very fruitful. An individual should adopt what is good for the team, whether it clashes with personal style or not.
  • Too much work: Using the coding standards feels too much work if its value is not being seen. And this is true sometimes. Wrong policies can often lead to increase in time and effort without an equivalent increase in value.

The Solution

The best way to solve these problems is to include all the team members when the coding standards are formulated. If it not possible to include everyone, all should at least be educated on the coding standards and their advantages and asked for their feedback.

Coding standards, just like software processes, should be customized for every project. Different aspects of the project like team size, team skillset, deadline, project, nature (distributed, onsite/offshore, …) should be considered. Using one-for-all coding standards usually results in misalignment between the actions and project’s goal. Sometimes this can also require customization to project management or organizational techniques.

A project configuration contains multiple policies and coding standards might overlap with some of them, e.g., exception-handling policy is closely related with coding standards. Specific care should be taken so that they don’t clash with each other.

Various tools are available to check compliance with coding standards. However, tools can never ensure the absolute. The best thing is to conduct code reviews, either by peers or seniors and encourage interaction in the developers.

Some more reading:

Technorati tags: , ,

Copyright Abhijit Nadgouda.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: