Derivation of a Measurement for Defining Ideal Number of Comments in Code

H. H. Yang, S. Williams, and R. McCrindle (UK)


Programming, Measurement, Education and Practice,Knowledge Discovery


Programmers spend a considerable amount of time reading, maintaining, and enhancing code that they did not originally write. Therefore, it is important that professional programmers must not only be able to write efficient and correct code, but must also be able to write it in a style that others can understand. Style consists of many features, including how the code is laid out and what variable names are used. Such features as these are difficult to measure quantitatively. Comments however, are a feature of style that can be numerated. By using knowledge discovery techniques it is possible to determine the relationship between the number of comments and the number of lines of code. Within this project there was an analysis of code presented in text books and from `real-world' open source projects (including GNU applications) in order to determine a measurement related to the use of comments within code. Overall it was found that in both cases there was an approximate ratio of 1 comment for every 3 lines of code. However it was noted that small amounts of code did not necessarily need to be commented.

Important Links:

Go Back