Presentation is loading. Please wait.

Presentation is loading. Please wait.

Metrics of Software Quality

Similar presentations


Presentation on theme: "Metrics of Software Quality"— Presentation transcript:

1 Metrics of Software Quality
5/11/2018 Prepared by Charlie Meyer, April 2008

2 What are software metrics?
Quantitative measurements distilled from data Distilled by measuring software development processes and actual source code Highlight areas that need work in specific nodes of code as well as generalizations about your code overall “You can’t control what you can’t measure” –Tom DeMarco 5/11/2018 Prepared by Charlie Meyer, April 2008

3 Limitations of metrics
Software metrics are intended to help programmers control and monitor software production, but… It’s difficult to determine “how much” software there is in a given program Can give a skewed impression of software, especially when calculated early in the software development process Can be difficult or complex to calculate, especially as the volume of code grows 5/11/2018 Prepared by Charlie Meyer, April 2008

4 Examples of software metrics
Lines of code Number of classes & interfaces Code to comment ratio Cyclomatic complexity Code coverage Bugs to lines of code ratio Cohesion Coupling Failed tests per build Version control commits per day Lines of code per commit 5/11/2018 Prepared by Charlie Meyer, April 2008

5 Terminology Node Program Flow graph
A block of source code, usually either a single line, a function/method, class, or package. A node can have multiple children, but only one direct parent Program A graph of all of the nodes that comprise the source code Flow graph A directed graph of all of the single line nodes connected with vertices where the possible flow of execution might proceed 5/11/2018 Prepared by Charlie Meyer, April 2008

6 Lines of code A key size attribute of software
Can be a good measure of software volatility, especially when tracked over the entire development process Can be used as the basis for other metrics, such as the bugs:code and tests:code ratios 5/11/2018 Prepared by Charlie Meyer, April 2008

7 Code to comment ratio We’ve already seen how important commenting is to developing quality code This metric puts a numerical value on the amount of inline documentation in a piece of software Gives developers warning on when code needs to be documented 5/11/2018 Prepared by Charlie Meyer, April 2008

8 Cyclomatic Complexity
Directly measures the number of linearly independent paths through source code CC = E - N + p where E = the number of edges of the program’s flow graph N = the number of nodes of the graph p = the number of connected components of the graph If code contains no decisions, then CC=1, if a piece of code contains a binary if statement, CC=2, etc… 5/11/2018 Prepared by Charlie Meyer, April 2008

9 Cyclomatic complexity cont.
Upper bound on the number of unique test cases required to have complete coverage of a given branch Commonly used thresholds: Cyclomatic Complexity Risk Evaluation 1-10 A simple program without much risk 11-20 More complex, moderate risk 21-50 Complex & high risk >50 Practically untestable, very high risk 5/11/2018 Prepared by Charlie Meyer, April 2008

10 More cyclomatic complexity…..
Lower CC contributes to a program’s understandability and indicates that it is more easily modifiable Generally, the greater CC becomes, the more complex and unmaintainable the code becomes Greater cyclomatic complexity indicates a greater learning curve for new developers 5/11/2018 Prepared by Charlie Meyer, April 2008

11 Code coverage A metric that describes to extent to which the source code of a program has been tested Different degrees of code coverage: Function coverage - Has each function in the program been executed? Statement coverage - Has each line of the source code been executed? Condition coverage - Has each evaluation point (such as a true/false decision) been executed? Path coverage - Has every possible route through a given part of the code been executed? Entry/exit coverage - Has every possible call and return of the function been executed Some of the above are connected together 5/11/2018 Prepared by Charlie Meyer, April 2008

12 Code coverage & unit tests
Indicator of how well your tests actually test your code Lets you know if you have enough tests in place Allows you to maintain the quality of your test suite over the lifetime of the project 5/11/2018 Prepared by Charlie Meyer, April 2008

13 How code coverage works (in java)
1. compile the source code 2. instrument the compiled class files, excluding the compiled test cases. This adds the necessary information to allow for… 3. Collect runtime data 4. merge the runtime data into a auditable report When the tests are executed, the extra info added in when the files were instrumented will write out exact coverage data to disk 5/11/2018 Prepared by Charlie Meyer, April 2008

14 Cohesion Cohesion is a measure of how strongly- related the various responsibilities of a software module are A node is usually deemed to have “high cohesion” or “low cohesion” High Cohesion can indicate many things about code, including the extent of reuse of code and readability 5/11/2018 Prepared by Charlie Meyer, April 2008

15 Disadvantages of low cohesion
Increased difficulty in understanding nodes of source code Increased difficulty in maintaining source code - changes will affect multiple nodes, changes in one node will require changes in many other nodes Increased difficulty in reusing a node of source code, since most other nodes will not need the functionality that a node with low cohesion provides 5/11/2018 Prepared by Charlie Meyer, April 2008

16 Coupling Coupling is the extent to which a node relies on the other nodes in the source code Nodes can be called either “loosely/weakly coupled” or “strongly/tightly coupled” Loose coupling indicates high cohesion! Loose coupling refers to a relationship between nodes such that one node interacts with the other nodes via a stable interface and does not need be concerned with the internal implementation of the other nodes 5/11/2018 Prepared by Charlie Meyer, April 2008

17 Types of coupling Content coupling (tightest) Common coupling
is when one node modifies or relies on the internal workings of another node Common coupling is when nodes share the same global data External coupling Is when nodes rely on an external data format Data coupling Is when nodes share data through parameters Message coupling (loosest) Is when modules are not dependent on each other, they use a public interface to communicate 5/11/2018 Prepared by Charlie Meyer, April 2008

18 Methods for decreasing coupling and increasing cohesion
Transmit messages between nodes in a flexible format (such as XML) Use public interfaces to communicate messages between nodes where a file format is not required Separate code into nodes that perform logical chunks of work (example: MVC pattern) Write code such that the implementation of a given node of code is independent from how it is used by other nodes 5/11/2018 Prepared by Charlie Meyer, April 2008

19 Free tools for auditing software
(java) (c, c++) Many other open source alternatives exist, google is your friend There are also commercial alternatives targeted for larger projects 5/11/2018 Prepared by Charlie Meyer, April 2008

20 Works cited http://en.wikipedia.org/wiki/Software_metric
atic_body.html tro.html uter_science%29 uter_science%29 5/11/2018 Prepared by Charlie Meyer, April 2008


Download ppt "Metrics of Software Quality"

Similar presentations


Ads by Google