Software Metrics *** state of the art, weak points and possible improvements Gordana Rakić, Zoran Budimac Department of Mathematics and Informatics, Faculty of Sciences, University of Novi Sad Melinda Tóth Eotvos Lorand University Budapest
Contents Abstract Introduction State of the Art Motivation Recursion Aware Complexity Conclusion Future Work
Abstract By target Process Product Resources By availability Internal External By measurement object Size Complexity Structure Architecture By applicability Specification Design Source code … (Some of) Software metrics classifications
Abstract Code complexity is measured by “old” metrics Inconsistency between the tools [Novak and Rakic, 2011] [Lincke et al. 2008] Metrics algorithm are sometimes adapted during the implementation according to Programming language Programming paradigm Programming style …
Question Could some of these changes be generalized by introducing new metrics?
Contents Abstract Introduction State of the Art Motivation Recursion Aware Complexity Conclusion Future Work
Software quality Attributes of Product Quality (not only the software product) user point of view functionality usability reliability efficiency portability producer point of view maintainability
Maintainability ISO 9126: maintainability of software product expresses easiness of making changes during the product life cycle is formally divided into analyzability, changeability, stability, and testability. strongly depends on readability and clarity of the source code. source code complexity Sometimes including code size and data organization and usage.
Contents Abstract Introduction State of the Art Motivation Recursion Aware Complexity Discussion Conclusion Future Work
State of the Art Complexity and size metrics LOC Halstead Cyclomatic Complexity ... Derived metrics
Cyclomatic Complexity Expresses number of linearly independent paths through the program Calculates the value based on number of control flows in the program [McCabe, 1976]
Cyclomatic Complexity Can underestimate or overestimate complexity [Vinju and Godfry, 2012] Derived metrics and modifications of CC: for OO languages WMC [Chidamber and Kemerer, 1993] for functional languages number of branches of recursion [Király and Kitlei, 2011] CC calculated on the graph built by in-lining the function ...
Question How RECURSION affect complexity and maintainability? How to measure it?
Contents Abstract Introduction State of the Art Motivation Recursion Aware Complexity Conclusion Future Work
Motivation Trends Multilingual projects Multi-paradigm languages … Tending to simplicity in programming we go from introducing recursion to increase maintainability to long chain of (recursive) calls which decreases maintainability
Motivation Control Flow Graph (CFG) One control flow graph represents one function/procedure/method/etc. Cyclomatic Complexity is used to measure number of paths in CFG Problem: Functions are not independent units => CFGs should be connected to give real picture
Motivation Program: set of the interconnected functions Represented by directed graph of higher level nodes of CFGs connected in a graph Available metrics measuring communication between functions: Number of input links Number of output links There are no metrics measuring complexity by observing the paths through the graph higher level equivalent to CC
Motivation sum(a, b){ sum=0; if (a = b) { sum := a + b; } else if (a>b){ while (a > b){ sum += a; a--; } sum += b; } else{ while (b > a){ sum += b; b--; } sum += a; } return sum; }
Motivation sum_max(max, min){ sum = 0; while (max > min){ sum += max; max--; } sum += min; return sum; } sum(a, b){ sum=0; if (a = b) { sum := a + b; } else if (a>b){ sum:= sum_max(a, b); } else{ sum:= sum_max(b, a); } return sum; }
Motivation sum(a, b){ sum=0; if (a = b) { sum := a + b; } else if (a>b){ sum+= a + sum(a-1, b); } else{ sum:= b + sum(b-1, a); } return sum; }
Parameters of complexity Local control flow complexity for each observed CFG Global control flow complexity complexity of the interactions between observed CFGs the length of the chains of calls the length of chains when there are closed chains of calls (recursion)
Contents Abstract Introduction State of the Art Motivation Recursion Aware Complexity Conclusion Future Work
Recursive Complexity LoR: Length of the Recursion number of branches (which is equivalent to the number of nodes) in the recursive chain
Q1: How to define Recursive Complexity (RC) if we know the Length of Recursion (LoR)? RC = LoR ??? In this case n self recursions have the same weight as one recursion whose chain contains n nodes Answer: not good enough RC = LoR 2 ??? Show case: mutual recursion of two functions four self-recursions Open question: are these two cases the similarly maintainable
Q2: How to define Overall Path Complexity (OPC) if we have in mind the definition of Cyclomatic Complexity (CC) and Recursive Complexity (RC) ???
Demonstration of OPC calc1(A)-> f(A). f(0) -> 1; f(N) -> g(f(N-1)) + calc1(10). g(0) -> 1; g(N) -> h(g(N-1)). h(0) -> 0; h(N) -> case N of 1 -> 1; 2 -> f(h(N-1)) end.
Demonstration of OPC
Contents Introduction State of the Art Motivation Recursive Complexity Conclusion Future Work
Conclusion Numerous complexity and maintainability metrics but still some gaps To fill the gap we propose introducing: Recursive Complexity Overall Path Complexity Implemented and tested several variations of this recursion aware metrics Implementation included in RefactorErl
Contents Introduction State of the Art Motivation Recursive Complexity Discussion Conclusion Future Work
To implement RC and OPC Integrate with the language independent SMIILE tool (SSQSA) [Budimac et al, 2012] Validate on broader range of examples To explore if there is correlation between OPC and Other metrics Execution time …
Gordana Rakić, Zoran Budimac Department of Mathematics and Informatics, Faculty of Sciences, University of Novi Sad Melinda Tóth Eotvos Lorand University Budapest