So sánh các kiểu biến và sử dụng của họ (ví dụ, khi sử dụng số nguyên ngắn trong C so với Boolean, khi sử dụng độ chính xác duy nhất so với hai điểm nổi chính xác, và vv). Sử dụng trực tuyến mở rộng của mã thông qua macro so với các cuộc gọi thủ tục | 400 8 ENGINEERING CONSIDERATIONS Figure Flow graph for gyro compensation code for the inertial measurement unit Laplante03c . or how intensively the programming language is used. Halstead s metrics are computed using the following slightly modified algorithm First find ni. This is essentially the number of distinct syntactic begin-end pairs or their equivalent called operators. Next find n2 the number of distinct statements. A statement is determined by the syntax of the language for example a line terminated by a semicolon is a statement in C. Next count Ni the total number of occurrences of ni in the program. Then count N2 the total number of occurrences of operands or n2 in the program. From these statistics the following metrics can be computed. The program vocabulary n is defined as n n1 n2 The program length N is defined as N Ni N2 The program volume V is defined as V N log2 n The potential volume V is defined as V 2 n2 log2 2 n2 METRICS 401 The program level L is defined as L V V where L is a measure of the level of abstraction of the program. It is believed that increasing this number will increase system reliability. Another Halstead metric measures the amount of mental effort required in the development of the code. The effort E is defined as E V L Again decreasing the effort level is believed to increase reliability as well as ease of implementation. In principle the program length N can be estimated and therefore is useful in cost and schedule estimation. The length is also a measure of the complexity of the program in terms of language usage and therefore can be used to estimate defect rates. Halstead s metrics though dating back almost 30 years are still widely used and tools are available to completely automate their determination. Halstead s metrics can also be applied to requirements specifications as well as to code by adapting the definitions of operator and statements. In this way comparative statistics can be .