SIMPLIFIED READABILITY METRICS Chung Yung Department of Information Systems New York University Leonard N. Stem School of Business 44 West 4th Street, Suite 9-1 70 New York, NY 10012-1 126 yung@edgar.stem.nyu.edu January 6,1997 Working Paper Series Stern #IS-97- 1 Center for Digital Economy Research Stem School of Business IVorking Paper IS-97-01 Extended Abstract This paper describes a new approach to measuring the complexity of software systems with considering their readability. Readability Metrics were first proposed by Chung and Yung 181 in 1990. Software industry uses software metrics to measure the complexity of software systems for software cost estimation, software development control, software assurance, software testing, and software maintenance [3], [71, [9], 151, [18]. Most of the software metrics measure the software complexity by one or more of the software attributes. We usually class@ the software attributes that software metrics use for measuring complexity into three categories: size, control flow, and data flow [5], f71. All the three categories concern with the physical activities of software development. Readability Metrics have been outstanding among the existing software complexity metrics for taking nonphysical software attributes, like readability, into considerations [8]. The applications of Readability Metrics are good in indicating the additional efforts required for less readable software systems, and help in keeping the software systems maintainable. However, the numerous metrics and the complicated formulas in the family usually make it tedious to apply Readability Metrics to large scale software systems. In this paper, we propose a simplified approach to Readability Metrics. We reduce the number of required measures and keep the considerations on software readability. We introduce our Readability model in a more formal way. The Readability Metrics preprocesses algorithm is developed with compilers front-end techniques. The experiment results show that this simplified approach has good predictive power in measuring software complexity with software readability, in addition to its ease of applying. The applications of Readability Metrics indicate the readability of software systems and help in keeping the source code readable and maintainable. Center for Digital Economy Research Stem School of Business IVorking Paper IS-97-01 Simplified Readability Metrics Chung ~ung* Department of Information Systems Leonard N. Stern School of Business New York University Abstract This paper describes a new approach to measuring the complexity of software systems with considering their readability. Readability Metrics were proposed by Chung and Yung [8] in 1990. Readability Metrics have been outstanding among the existing software complexity metrics for taking nonphysical software attributes, like readability, into considerations. The applications of Readability Metrics are good in indicating the additional efforts required for less readable software system, and help in keeping the software systems maintainable. However, the numerous metrics and the complicated formulas in the family usually make it tedious to apply Readability Metrics to large scale software system. In this paper, we propose a simplified approach to Readability Metrics. We reduce the number of required measures and keep the considerations on software readability. We introduce our Readability model in a more formal way. The Readability Metrics preprocesses algorithm is developed with compilers front-end techniques. The experiment results show that this simplified approach has good predictive power in measuring software complexity with software readability, in addition to its ease of applying. The applications of Readability Metrics indicate the readability of software systems and help in keeping the source code readable and maintainable. 1. Introduction It is widely conceived that more time and money are spent on maintaining existing software systems than on developing new ones [12]. More and more modern companies use a maintenance-based software development paradigm, in which * Chung Yung is currently reachable at yung@edgar.stern.nyu.edu. Center for Digital Economy Research Stem School of Business IVorking Paper IS-97-01 software is developed mainly by mowing the source code of existing software systems [21]. The maintainability of software systems becomes one of the most important issues in software industry. A lot of researches investigate in the techniques of improving software maintainability, software quality, and software reliability, and propose new methodologies of software metrics, which are applied to measuring software complexity and to monitoring the process of software development [3], [9], [15], [18]. The maintainability of software systems is dnven by their complexity [2]. The cost of maintain legacy program is enormous because of the program's complexity [21]. There are plenty of materials dedicated to measure and analyze the complexity of software systems [4], [5], [12], [14], [Z], [23]. Many metrics are famous with their power in predicting software complexity, such as software science [15], cyclomatic measurement [lq, and so on. They measure the complexity of software systems by quanbfying certain attributes of software, such as software size, control flow, data flow, and others 151, m- Size is one of the most important attributes of software systems [25]. It dominates the cost for the systems both in man-power and in budget, and both for development and for maintenance. Size based software metrics indicate the complexity of a software system mainly by its size attributes. These size base metrics help in predicting the cost for maintaining the system [5]. Control flow and data flow are two of the most important attributes, other than size, of software systems [5], m, [9]. Control flow metrics capture the relation between the logic structures in a program with its complexity, while data flow metrics indicate the complexity of software system by their data dependency. Readability is another important attributes of software systems that gives substantial affect on software maintainability r/l, [8]. The software systems with less readable source code are recognized as more difficult to maintain than those with more readable source code. In contrast to the software attributes like size, control flow, and data flow, software readability attribute is more about psychological activities rather than physical ones. Readability Metrics are a fdy of software metrics that measure software complexity with taking readability into considerations. The family of Simplified Readability Metrics is a new approach to measuring the Center for Digital Economy Research Stem School of Business IVorking Paper IS-97-01 complexity of software systems. In addition to simphfying Readability Metrics, we develop a new readability model. With the new readability model, we expand the software science metrics with a family of Readability Metrics. In particular, the magnitudes of Readability Metrics indicate the readability of software systems in percentage with respect to the readability of the algorithm implemented. And, we include the algorithms of Readability Metrics preprocesses and a few modifications we have made since Readability Metrics was published. This paper is organized as such. The following section describes the attributes used by existing software metrics for measuring software complexity. We class* them into three categories and give examples of the metrics in each category. Section 3 is a more formal description on our Readability model. In Section 4, we introduce our new approach to Readability Metrics. We include the Readability Metrics preprocesses algorithm. We also show how the simplified approach measures the complexity of software systems by their readability. We include the results of one experiment set in Section 5. And, at last is a brief conclusion. 2. Attributes for Measuring Software Complexity We distinguish the existing software complexity metrics by the attributes they use for measuring and we usually class* them into three categories: size based metrics, control flow based metrics, and data flow based metrics [5]. Please note that all the three categories of software attributes used for measuring software complexity are more about the physical activities in the software development life-cycle while software readability is more about the physical activities. The size of a software system is a popularly conceived software attribute that affects software complexity [71, [25]. The size based metrics measure the complexity of software systems by their sizes. However, it is still arguable what is the basic unit of software size. The popularly used size based metrics include token counts, lines of code, software science, and so on. A few empirical results indicated that the control flow complexity is well correlated with the overall complexity of a software system [12], [18], [27]. The control flow based metrics measure the complexity of software systems on their control flow graphs. Two of the most famous control flow based metrics are knots metrics and cyclomatic metrics. McCabe and Butler showed that cyclomatic metric also contributes in software testing Center for Digital Economy Research Stem School of Business IVorking Paper IS-97-01 and software maintenance, in addition to software complexity measurement [19]. Data flow based metrics measure the complexity of software systems by the inter and intra data dependency among modules [5], [20]. The results of numerous studies and experiments indicated that data dependency of a software system has a signhcant effect on the software complexity [13], [14]. The widely used data flow based metrics include Oviedo's metrics, live variable metrics, variable span metrics and Chung's metrics [4]. In the following of this section, we briefly introduce one family of software complexity metrics in each category as an example and as a comparison, 2.1 Saftware Science In the early 1970'~~ investigated on measuring the complexity of software by analyzing its source code, which is called sop?ome science. Software science used a series of simple formulas to measure a few characteristics of a software system [16]. There are many papers published and concluded that the predictive power of software science is pretty well by Gordon [14], Woodfield [27J, and other researchers. The details about software science are originally appeared in a monograph, Elements of Software Science [15]. A few later materials also described the metrics [9], [11], [23], [24]. Halstead defined four basic metrics computable from the program source code: nl = the number of unique operators n2 = the number of unique operands N1 = the total number of operator occurrences N2 = the total number of operand occurrences where, the operands are the variables or constants, and the operators are the symbols or combinations of symbols that affect the values or the ordering of operands. For example, the C subprogram Matrixchain1 in Fig. 1 has 10 distinct operators and 12 distinct operands. The total number of operator occurrences is 44, and the total number of operand occurrences is 52. Center for Digital Economy Research Stem School of Business Working Paper 1s-97-01 MatrixChainl ( ) { int n = length; int i, j, k, 1, q; for (1=2; l<=n; 1++) { for (i=l; i<=n-lfl; i++) { j=i+l-1; m[i] [j] = 50000; for (k=i; k of n matrices, where for i = 1, 2, ..., n, matrix Ai has dimension pi-I x pi, fully parenthesize the product AI, A;, ..., An in a way that minimizes the number of scalar multiplications [lo]. In the implementation of Center for Digital Economy Research Stem School of Business IVorking Paper IS-97-01 Matrixchainl, there is an statement with a highly compound expression which includes three additions, one subtraction, and two multifications. Suppose that we have another version of implementation of the same algorithm as Matrixchainl implements with a different programmjng style, shown as Matrixchain2 in Fig.2. The only difference is on the statement calculating q. In MatrixChain2, the statement with the highly compound expression is split into two statements, and the new variable has a logically clear definition. To most of software engineers, Matrixchain2 is much more readable than MatrixChainl. When maintaining software systerns, the long compound statements, like the one in MatrixChainl, usually take much more time for software engineers to understand what it does. MatrixChain2 ( ) { int n = length; int i, j, k, 1, q, r; for (1=2; l<=n; 1++) I for (i=l; i<=n-l+l; i++) { j=i+l-1; m[i] [j] = 50000; for (k=i; k