Given that usually the compiler does not complain about the coding style of a program (i.e. missing white spaces, indentation, long lines of code, name conventions, and comments), developers care only for the functionality of their programs and not for the maintainability. However, this can be harmful for the understanding and maintenance of modern software systems. This post discusses the importance of writing programs based on specific coding guidelines.
When we start to learn a programming language, for example Java, we learn to follow some specific guidelines (e.g. from Google and Oracle) in order to make our programs concise and clear to others and ourselves. In fact, the moment we code, we do not care if we will be able to read and understand our code after three weeks or a month; but if we cannot understand our own code, how others could understand our code and add new features or fix our bugs?
By looking at a set of large open source projects, we found that most of the top open source communities are quite strict about the coding conventions that developers’ use. Some of the projects note that clumsy commits can be rejected due to coding convention violations. In addition, some projects run special hooks during the addition of a new patch to the trunk to check specific standards. In my lab, we recently studied the developer documentation of 25 well-known open source projects/families to search for their style guidelines and how these are enforced.
According to Table 1, 7 out of 25 projects (28%) are using automated methods (mandatory and voluntary) to ensure coding style conformance. From these projects, Linux, gcc, Cpython and illumos-gate instruct commiters to check their source code for coding style inconsistencies, before each new patch commit. The remaining of these projects suggests the use of automatic style check (e.g. by adapting the configuration of source code editors and IDES, and executing third-party scripts) without imposing the use of checks before each commit. In addition, we found that 17 out of 25 projects (68%) are using specific guidelines (mandatory and voluntary). Projects with mandatory checks, such as FreeBSD, Blender, Perl, and PHP, have broad guidelines and encourage committers to conform to the projects’ coding style in order to be possible for their commits to get been accepted by reviewers. Regarding projects with voluntary checks, such as PostgreSQL, VLC, and KDE, they provide shorter guidelines with limited examples without imposing strict coding style before each new commit. Finally, we found that 6 out of the 25 projects (24%) have narrow or loose checks regarding coding styles. This can be possibly related to the business models of these projects.