Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Metrics 1.

Similar presentations


Presentation on theme: "Software Metrics 1."— Presentation transcript:

1 Software Metrics 1

2 Definitions Measure quantitative indication of extent, amount, dimension, capacity, or size of some attribute of a product or process e.g., Number of Errors Metric quantitative measure of degree to which a system, component or process possesses a given attribute. e.g., Number of errors found per person hour

3 Why Measure Software? Determine the quality of the current product or process Predict qualities of a product/process Improve quality of a product/process

4 Motivation for Metrics
Estimate the cost & schedule of future projects Evaluate the productivity impacts of new tools and techniques Establish productivity trends over time Improve software quality Forecast future staffing needs Anticipate and reduce future maintenance needs

5 Example Metrics Defect rates Error rates Measured by:
Individual Component During development Errors should be categorized by origin, type and cost

6 Metric Classification
Products Explicit results of software development activities Deliverables, documentation, by products Processes Activities related to production of software Resources Inputs into the software development activities Hardware, knowledge, people

7 Product vs. Process Process Metrics Product Metrics
Insights of process paradigm, software engineering tasks, work products, or milestones Lead to long term process improvement Product Metrics Accesses the state of the project Track potential risks Uncover problem areas Adjust workflow or tasks Evaluate teams ability to control quality

8 Types of Measures Direct Measures (internal attributes)
Cost Effort LOC Speed, Memory, … Indirect Measures (external attributes) Functionality Quality Complexity Efficiency Reliability Maintainability

9 Size-Oriented Metrics
Size of the software produced LOC – Lines of Code KLOC – 1000 Lines of Code SLOC – Statement (Source) Lines of Code (NLOC – Non-Commented Lines of Code) Function Points Typical Measures Errors/KLOC Defects/KLOC Cost/LOC Documentation Pages/KLOC

10 LOC Metrics Easy to use Easy to compute
Language and Programmer dependent Not a very good standard “Measuring software productivity by Lines of Code is like measuring progress on an airplane by how much it weighs.” Bill Gates

11 Lines of Code? What about whitespace? Comments? Consider:
Copy (char *p, *q) { while (*p) *q++ = *p++; } Copy (char *p, *q) { while (*p) *q++ = *p++; }

12 Lines of Code: Language Matters
s/D33_Planning.pdf SLOC per Function Point Assembly 320 C 150 Fortran 106 Pascal 91 LISP 64 Smalltalk 21

13 Lines of Code… …is a valid metric when Same Language
Standard Formatting Code has been reviewed

14 Depth of Inheritance Tree
DIT is the maximum length from a node to the root of the tree (base class) Assumptions The deeper a class in the hierarchy, the greater the number of methods it will probably inherit which makes it harder to predict its behavior Deeper trees involve greater design complexity since more classes and methods are involved Deeper classes in the tree have a greater potential for reusing inherited methods Assumptions 1 and 2 tell us that having a higher number for depth is bad. However assumption 3 indicates that a higher number for depth is good for potential code reuse.

15 Complexity Metrics LOC – a function of complexity
Cyclomatic Complexity Cohesion and Coupling

16 Cyclomatic Complexity
A measure of logical (structural) complexity Gives an upper bound on the number of tests necessary to execute every edge of the control graph Number of independent paths (branches - if, while for) through the procedure Cyclomatic Complexity Risk Evaluation 1-10 A simple module without much risk 11-20 A more complex module with moderate risk 21-50 A complex module of high risk 51 and greater An untestable module of very high risk

17 Calculating Cyclomatic Complexity
= (1 + IFs + Loops + Cases) where IFs is the number of IF operators in the function Loops is the number of loops in the function Cases is the number of switch branches in the function (without default)

18 Cyclomatic Complexity Example
public override void UpdateInput() { // Get the current gamepad state. KeyboardState currentState = Keyboard.GetState(PlayerIndex.One); Keys [] keysPressed = currentState.GetPressedKeys(); foreach (Keys key in keysPressed) if (!previousKeyboardState.IsKeyDown(key)) if (commands.ContainsKey((int)key)) commands[(int)key].Execute(); // Update previous gamepad state. previousKeyboardState = currentState; }

19 Cyclomatic Complexity Example (cont)
public override UpdateInput () foreach if ! if commands[].Execute (); done = (1 + 2{Ifs} + 1{Loops} + 0{Cases}) = 4

20 Visual Studio Code Metrics
Calculated from Source Code Maintainability Index Cyclomatic Complexity Depth of Inheritance Class Coupling Lines of Code

21 Maintainability Index
The maintainability index gives an indication of how easy it should be to understand and modify the code. The index is 0 <= index <= 100 with lower numbers indicating code that may be more difficult to work with (maintain) Based upon several other values Cyclomatic complexity Lines of code Halstead Volume Computational complexity of algorithms, determined by the number of operands and operators used. Fewer of each leads to better maintainability

22 Cyclomatic Complexity
To reduce the cyclomatic complexity you should consider refactoring to extract methods If a method has a high value due to a large set of switch cases you might consider refactoring the code to use a design pattern such as the Strategy pattern

23 Class Coupling Indicates the amount of coupling between types in your source code. The value is the number of other types that a class uses through Properties Fields Method parameters Return values If you see the class coupling warning there is a high likelihood that your code requires refactoring

24 Lines of Code LOC describes the amount of source code that exists in your project or solution If the value is high for an individual member, consider refactoring LOC is not the number of lines of C# code; actually based upon the number of lines of intermediate language (IL) code after building the solution The value includes some, but not all, automatically generated code

25 Visual Studio Code Metrics
Demonstration

26 ?

27 References


Download ppt "Software Metrics 1."

Similar presentations


Ads by Google