Readability of Code – Increasing Productivity in Development Teams

Readability of Code – Increasing Productivity in Development Teams

Importance of a Consistent Coding Convention

 

Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices, and methods for each aspect of a program written in that language. Coding conventions can significantly enhance the readability of source code for the individual.

 

The most prominent issue, of course, is that coding conventions/styles can be very subjective – whether its naming conventions, indentation, declarations etc. There will usually be different preferences within a team of developers. In our team, we predominantly code in C# using Visual Studio. We had many differences in our coding conventions which inevitably proved to be frustrating, as the time it took to read and understand each other’s code needlessly increased. To fix this problem, we agreed on one coding convention and a set of rules to follow.

 

There are many benefits to using a consistent coding convention within a team. As mentioned previously, readability is the focus here. It is said that 40%–80% of the lifetime cost of a piece of software goes to maintenance. It is evident that code must be written with maintenance in mind. It is also very unlikely for the original developer/s to maintain the code for its full lifetime, delegating it to an outside developer. To build further onto this point, it’s good practice to write a script with the idea of the script being shipped as a clean, well packaged product as it very well might be. This would encourage the developer to write a script that is readable by largest amount of people.

 

In our case, we agreed on an indentation style, method naming convention etc. As these elements are for the most part subjective, I cannot give a definitive best choice. However, there are some rules we created that can greatly enhance readability:

 

  • Descriptive variable names:
    • It can be tempting to write a very short variable name as at first glance over a script, you will see less code on the screen. While it will appear less messy, you will find yourself struggling to figure out what that variable means. A long variable name that describes what that variable is will always beat a short variable when it comes to maintainability.

 

  • Documenting complicated methods/ variables:
    • Sometimes the variables can be so complicated that you need a sentence to describe them. It is in your best interest to create a comment where the variable is created explaining in detail what that variable does. The same applies to a method. If you feel that a method is more complicated than usual, a comment can seriously help other developers to understand it.

 

  • Using tabs rather than spaces:
    • This one just makes your code look neater as occasionally you will see developers using a random amount of spaces between different lines of code. A tab keeps a consistent amount of whitespace behind the line of code.

 

In conclusion, readability of code promotes increased productivity in the workplace. Here at Nebula, we value the readability of our code immensely and feel that creating a consistent coding convention is essential for every development team.