Design-sensitive metric thresholds based on design roles - Dósea, Marcos Barbosa (2021)
State-of-the-art techniques and Automated Static Analysis Tools (ASATs) for identifying code smells rely on metric-based assessment. However, most of these techniques have low accuracy. One possible reason is that source code elements, such as methods implemented according to different design decisions, are assessed through the same generic threshold for each metric. Other possible reason is that these metric thresholds are usually derived from classes driven by different design decisions. Using generic metric thresholds that do not consider the design context of each evaluated class can generate many false positives and false negatives for software developers. Our goal is to propose design-sensitive techniques to derive contextual metric thresholds. Our primary hypothesis is that using the design role played by each system class to define this context may point out more relevant code smells to software developers. We conducted some empirical studies to define the proposed techniques. Firstly, we performed a large-scale survey that showed that practitioners recognize difficulties in fitting ASATs into the software development process. They also claim that there is no routine for application. One possible reason practitioners recognize that most of these tools use a single metric threshold, which might not be adequate to evaluate all system classes. Secondly, we conducted an empirical study to investigate whether fine-grained design decisions also influence the distribution of software metrics and, therefore, should be considered to derive metric thresholds. Our findings show that the distribution of metrics is sensitive to the following design decisions: (i) design role of the class (ii) used libraries, (iii) coding style, (iv) exception handling, and (v) logging and debugging code mechanisms. We used these findings to propose two new techniques to derive design-sensitive metric thresholds using the class design role as context. Then, we carried out two large-scale empirical studies to evaluate them. The first study showed that our proposed techniques improved precision according to developers' perceptions. Since it is impossible and tiring to perform a complete source code quality assessment with developers, we conducted a second study mining the evolution of software projects from popular architectural domains. We found that our techniques improved recall to point out methods effectively refactored during software evolution.