WebMetrics: A tool for improving software development. Marco Scotto1, Alberto Sillitti2, Tullio Vernazza1, Giancarlo Succi2. 1DIST â Università di Genova, Via ...
WebMetrics: A tool for improving software development Marco Scotto1, Alberto Sillitti2, Tullio Vernazza1, Giancarlo Succi2 1
DIST – Università di Genova, Via Opera Pia, 13, I-16145 Genova, Italy {scotto, tullio}@dist.unige.it
2
Free University of Bozen, Piazza Domenicani, 3, I-39100 Bolzano, Italy {Alberto.Sillitti, Giancarlo.Succi}@ unibz.it Abstract
Improve quality control and thereby code quality by directly supporting adherence to programming practices and corporate coding standards.
One of the biggest problems of software development is the management of software quality, both in terms of defects and easiness of maintenance. Software production and evolution is intangible. This nature has caused problems for software developers since there is no sense feedback. The obvious idea is for future development to learn from past experience: avoiding practices leading to poor software quality and emphasizing those increasing it. Static analysis is a way to provide feedback in software development. This paper presents WebMetrics, an extensible tool for static analysis based on software metrics
This paper presents WebMetrics, an extensible tool for static analysis based on software metrics. Software metrics is an area which tries to quantify different aspects of software development. Such measures can provide useful insights to both developers and researches. The article is organized as follows: section 2 gives a brief survey about static analysis techniques; section 3 describes the design and the implementation of WebMetrics; finally, section 4 draws the conclusions.
Keywords
2. Static Analysis
Static Analysis, Software Metrics
1. Introduction A very promising and proven approach to reducing test effort and shortening the development cycle is the detection of defects very early in the development cycle through static analysis. Static analysis tools use sophisticated parsing techniques to analyze the code in the developer’s workbench and are able to detect many programming errors at initial compile time and before more traditional testing strategies. In particular, static analysis can:
Reduce time to market by cutting off testing time due to earlier detection of potential software errors;
Significantly reduce review effort by automating a major portion of the inspection process (compliance with coding standards, usage of best programming practices);
Static analysis can be defined as the process of examining source or compiled code without executing it. Static analysis can test a great number of different programming constructs for compliance with good programming practices. Each check can provide a description of the good programming practice compliance violation (rule) as well as advice as to what the associated good programming practice could be (observation). The rule and the observation together indicate how relevant programming practices are violated as well as how the code can be improved to satisfy guidelines. There are two kinds of analysis:
Rule based analysis, they verify the compliance with good coding practices. An example of such tests in Java is the verification that a catch clause contains at least one statement. Metric based analysis, they calculate code quality metrics such as Static Path Count, Cyclomatic Complexity and Nesting Depth. The analyzer uses these values to generate suggestions based on user defined rating values (maximum or minimum allowed
values). A notification is generated each time a method/class has a metric value outside the allowed range.
3. WebMetrics WebMetrics is a static analysis tool based on software metrics. It provides feedback by identifying methods and classes for which safe range are violated. Software metrics can be extracted from multiple source languages: C/C++, Java, Smalltalk, and other languages under development. The system is completely written in Java and the parsers have been developed using JavaCC [1]. To parse a project, all the code must be syntactically correct. This is best verified by making sure that the source code compiles before attempting to use the tool. At present, the tool is able to extract the following metrics: Procedural code metrics; Object-Oriented design metrics. Procedural code metrics measure internal attributes of functions and procedures, so they are applicable to almost all programming languages. In particular, the following metrics are considered: Lines Of Code (LOC), McCabe Cyclomatic Complexity [2], Halstead Volume [3], Fan-In and Fan-Out [4]. Many Object-Oriented design metrics have been proposed [5, 6; 7]. One of the most referenced metrics suites is proposed by Chidamber and Kemerer (CK Metrics) [8]. CK Metrics suite is a set of six metrics which capture different aspects of an OO design, including complexity, coupling and cohesion. These metrics were the first attempt of OO metrics with a strong theoretical basis. The metrics suggested are: Weighted Methods per Class (WMC), Depth of Inheritance Tree (DIT), Number of Children (NOC), Coupling Between Object classes (CBO), Response For a Class (RFC), and Lack of Cohesion in Methods (LCOM). Several studies have been conducted to validate these metrics and have shown that CK metrics are useful quality indicators for predicting fault-prone classes [9, 10] and maintenance effort [11], as well as being significant economic variable indicators [12].
classes, interfaces, methods and attributes. This relations set is stored in a database in order to calculate metrics directly by performing SQL queries. This solution reduces the performance but allows the extraction of new metrics without additional effort. The architecture includes three main components (Fig. 1): 1.
Parser: each parser consists of a grammar parser, a symbol table, and supporting classes. The grammar parser recognizes the syntax of a particular language and it is written in JavaCC [1]. JavaCC is a tool able to generate parsers source code in Java, given a grammar as an input. It uses a top down LL(k) parsing algorithm [13]. The symbol table and all supporting classes are written in Java. The Common Interface module is shared among all parsers and it provides a standard API to report relations on the database.
2.
Database: it stores the relation set that represents the source code. The implementation is based on the open source DBMS MySQL [14]
3.
Analyzer: it calculates the metrics querying the relation set with the SQL language. Each metric is a class which implements the Measure interface. This is implemented according to the Strategy design pattern [15], in this way the analyzer can calculate each metric in exactly the same way through polymorphism. New metrics can be developed by adding a new class implementing this interface. Metrics calculated are reported through an XML [16] file. This file can be transformed with XSLT [17] into any kind of report. Moreover, in this way, it is possible to generate reports at different levels of aggregation. In our case, the XML file is transformed into a simple HTML page including the following metrics: CK Metrics Suite, LOC and McCabe Cyclomatic Complexity average per method (Fig 2).
3.1. Architecture The architecture of WebMetrics uses an intermediate abstraction layer to decouple language parsing from metrics extraction process. Parsers simply generate a set of intuitive relations, which a separate analyzer uses as input to compute metrics. Relations describe the interaction among different language entities, such as
Figure 1. Architecture overview
At run-time, the typical execution pattern is the following: the parser parses the source code and populates a symbol table. Then, each entry in the symbol table is asked to report its relations on the database; the report system is implemented according to the Visitor design pattern [15]; finally, the analyzer queries the relation set stored in the database to calculate the desired metrics and reports metrics highlighting entities for which metrics are out of range.
5. References [1] JavaCC – web site: http://javacc.dev.java.net/ [2] McCabe T., 1976, “A Complexity Measure”, IEEE Transaction on Software Engineering. [3] Halstead M. H., 1977. Elements of Software Science, Elsevier, Amsterdam. [4] Henry S.M., Kafura D.G., 1981. Software Structure Metric Based on Information Flow, IEEE Transactions on Software Engineering, Vol. 7, no 5, pp.545-522. [5] Briand L., Devanbu P., Melo W, 1996. An investigation into coupling measures for c++. Technical Report ISERN-96-08, ISERN. [6] Li W., 1998. Another metric suite for object-oriented programming. Journal of Systems and Software, 44:155.162. [7] Lorenz M., Kidd J., 1994. Object-Oriented Software Metrics. Prentice Hall Inc.
Figure 2. WebMetrics output
4. Conclusions and future work There is a growing interest in software tools that can analyze code as it is being written. In this paper, WebMetrics, a static analysis tool based on software metrics, has been presented. WebMetrics allows the developer to find earlier potential bugs, to avoid unnecessary complexity and to discover high maintenance areas. The most important feature of WebMetrics is its extendibility: it is straightforward to add new metrics simply by writing a query using SQL language. In this way, a metrics researcher needs to deal with a high level, metrics-oriented, intermediate representation when adding or modifying metrics to calculate. This spares the researcher from having to know intimidating language parsing concepts such as declaration, class specifiers, and base clauses. Future enhancements of the system will include rule based analysis in order to check the code for adherence to best programming practices. The integration with most widely used IDEs such as Eclipse, JBuilder, Netbeans, Microsoft Visual Studio, will provide another relevant enhancement. A parser for the C# language is under development and it will be integrated into a future version of WebMetrics
[8] Chidamber, R., Kemerer, F., 1994. A Metrics Suite for Object-Oriented Design. IEEE Trans.software Eng., Vol. 20, No. 6. [9] V. R. Basili, L. C. Briand, and W. L. Melo. A validation of object-oriented design metrics as quality indicators. IEEE Transactions on Software Engineering, 22(10):751.761, October 1996. [10] M. H. Tang, M. H. Kao and M. H. Chen. An empirical study of object-oriented metrics. In Proceedings of 6th IEEE International Software Metrics Symposium, 1999. [11] W. Li and S. Henry. Object-oriented metrics that predict maintainability. Journal of Systems and Software, 23:111.122, 1993. [12] S. R. Chidamber, D. P. Darcy, and C. F. Kemerer. Managerial use of metrics for object-oriented software: An exploratory analysis. In IEEE Transactions on Software Engineering, 24(8):629.639, August 1998. [13] Aho A.V., Sethi R., Ullman J.D, 1986. Compilers: Principles, Techniques and Tools, Addison-Wesley. [14] MySQL - web site: http://www.mysql.com.
[15] Gamma E., Helm R., Johnson R., Vlissides J., 1995. Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley. [16] XML (eXtensible Markup Language) specifications – web site http://www.w3.org/XML/ [17] XSLT (eXtensible Stylesheet Language Transformation) web site: http://www.w3.org/Style/XSL/