Software Metrics and Design Principles. What is Design?

Similar documents
Software Design Fundamentals. CSCE Lecture 11-09/27/2016

Introduction to System Design

Software Design. Software design is a blueprint or a plan for a computerbased solution for system

CS 292 Software Development

CHAPTER 4 HEURISTICS BASED ON OBJECT ORIENTED METRICS

Vragen. Intra-modular complexity measures. The uses relation. System structure: inter-module complexity

ARiSA First Contact Analysis

Unit-3 Software Design (Lecture Notes)

UNIT II Requirements Analysis and Specification & Software Design

The Software Design Process. CSCE 315 Programming Studio, Fall 2017 Tanzir Ahmed

Software Architecture and Design I

CHAPTER 4 OBJECT ORIENTED COMPLEXITY METRICS MODEL

A Study of Software Metrics

From Module To Objects

Measuring Complexity

System Design and Modular Programming

Modularity Guidelines for design in any programming language

SENG 421: Software Metrics

Software Design Heuristics

Software Metrics. Lines of Code

Introduction to Object Oriented Analysis and Design

Recap : UML artefacts. Black Box Requirements. Functional Specification. System. System. Test. Design. System. System. Development.

Modularity!! Guidelines for design! in any programming language!

Using Metrics To Manage Software Risks. 1. Introduction 2. Software Metrics 3. Case Study: Measuring Maintainability 4. Metrics and Quality

VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Darshan Institute of Engineering & Technology for Diploma Studies

What are the characteristics of Object Oriented programming language?

The Relationship between Slices and Module Cohesion

Design Process Overview. At Each Level of Abstraction. Design Phases. Design Phases James M. Bieman

Ch 1: The Architecture Business Cycle

Software Architecture

THE OBJECT-ORIENTED DESIGN PROCESS AND DESIGN AXIOMS (CH -9)

Impact of Dependency Graph in Software Testing

Quantify the project. Better Estimates. Resolve Software crises

5/9/2014. Recall the design process. Lecture 1. Establishing the overall structureof a software system. Topics covered

Software Testing: A Craftsman s Approach, 4 th Edition. Chapter 16 Software Complexity

CHAPTER 5 GENERAL OOP CONCEPTS

Anale. Seria Informatică. Vol. XVI fasc Annals. Computer Science Series. 16 th Tome 1 st Fasc. 2018

Elementary Concepts of Object Class

Measuring internal product attributes: structure. Basel Dudin

Software Development Methodologies

IMPACT OF DEPENDENCY GRAPH IN SOFTWARE TESTING

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Measuring the quality of UML Designs

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

Intro to: Design Principles

Classes and Objects. Object Orientated Analysis and Design. Benjamin Kenwright

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS SOFTWARE ENGINEERING

CAS 703 Software Design

In addition to name. Each variable in C program is characterized by its Type Scope Storage Class. Type Have already discussed

Project 1: Scheme Pretty-Printer

Comparing Software Abstractions Baby Steps. Michael Hansen Lab Lunch Talk 2011

Package understandbpmn

ClearSQL Code Metrics Inside

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

The Analysis and Design of the Object-oriented System Li Xin 1, a

All the subjective part of 2011 papers solved complete reference numbers

ADVANCED SOFTWARE DESIGN LECTURE 4 SOFTWARE ARCHITECTURE

By: Eng. Mohammed T. Abo Alroos

SOFTWARE PRODUCT QUALITY SOFTWARE ENGINEERING SOFTWARE QUALITY SOFTWARE QUALITIES - PRODUCT AND PROCESS SOFTWARE QUALITY - QUALITY COMPONENTS

Risk-based Object Oriented Testing

Effective Modular Design

Architectural Design

McCa!"s Triangle of Quality

Software Engineering Design Principles. Presented by Pratanu Mandal of CSE 3A Roll 54 JISCE

Sri Vidya College of Engineering & Technology

Object-Oriented Design

Sub- PPL Unit-I Class-SE Comp

WHAT IS SOFTWARE ARCHITECTURE?

Petros: A Multi-purpose Text File Manipulation Language

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Architecture CSE 403. Fallingwater by Frank Lloyd Wright

2IS55 Software Evolution. Software metrics (2) Alexander Serebrenik

Objectives. Architectural Design. Software architecture. Topics covered. Architectural design. Advantages of explicit architecture

Software Architectures. Lecture 6 (part 1)

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Software Architecture

The PCAT Programming Language Reference Manual

Chapter 2 Working with Data Types and Operators

What is a Programming Paradigm

Creating a Lattix Dependency Model The Process

Structured Analysis and Structured Design

10조 이호진 이지 호

Testing, Module To Object, Reusability

Metrics applicable to software design X. Yu & D.A. Lamb Department of Computing and Information Science, Queen's University, Kingston, Ontario, Canada

A comparative study of Programming by Contract and Programming with Exceptions

Architectural Decomposition & Representations Reid Holmes

CS504-Softwere Engineering -1 Solved Subjective Midterm Papers For Preparation of Midterm Exam

History of object-oriented approaches

ECE468 Computer Organization & Architecture. The Design Process & ALU Design

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

One size does not fit all

SYSTEM CONCEPTS. Definition of a System

System Design. Design: HOW to implement a system

Software Design. Levels in Design Process. Design Methodologies. Levels..

Stack Parameter Check

Ch 1: The Architecture Business Cycle

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

Software Architecture

Design Concepts and Principles

Transcription:

Software Metrics and Design Principles Chapters 5,8 What is Design? Design is the process of creating a plan or blueprint to follow during actual construction Design is a problem-solving activity that is iterative in nature In traditional software engineering the outcome of design is the design document or technical specification (if emphasis on notation)

Wicked Problem Software design is a Wicked Problem Design phase can t be solved in isolation Designer will likely need to interact with users for requirements, programmers for implementation No stopping rule How do we know when the solution is reached? Solutions are not true or false Large number of tradeoffs to consider, many acceptable solutions Wicked problems are a symptom of another problem Resolving one problem may result in a new problem elsewhere; software is not continuous Systems-Oriented Approach The central question: how to decompose a system into parts such that each part has lower complexity than the system as a whole, while the parts together solve the user s problem? In addition, the interactions between the components should not be too complicated Vast number of design methods exist 2

Design Considerations Module used often usually refers to a method or class In the decomposition we are interested in properties that make the system flexible, maintainable, reusable Abstraction Modularity Information Hiding Complexity System Structure Abstraction Abstraction Concentrate on the essential features and ignore, abstract from, details that are not relevant at the level we are currently working on E.g. Sorting Module Consider inputs, outputs, ignore details of the algorithms until later Two general types of abstraction Procedural Abstraction Data Abstraction 3

Procedural Abstraction Fairly traditional notion Decompose problem into sub-problems, which are each handled in turn, perhaps decomposing further into a hierarchy Methods may comprise the sub-problems and submodules, often in time Data Abstraction From primitive to complex to abstract data types E.g. Integers to Binary Tree to Data Store for Employee Records Find hierarchy in the data 4

Modularity During design the system is decomposed into modules and the relationships among modules are indicated Two structural design criteria as to the goodness of a module Cohesion : Glue for intra-module components Coupling : Strength of inter-module connections Levels of Cohesion. Coincidental Components grouped in a haphazard way 2. Logical Tasks are logically related; e.g. all input routines. Routines do not invoke one another. 3. Temporal Initialization routines; components independent but activated about the same time 4. Procedural Components that execute in some order 5. Communicational Components operate on the same external data 6. Sequential Output of one component serves as input to the next component 7. Functional All components contribute to one single function of the module Often transforms data into some output format 5

Using Program and Data Slices to Measure Program Cohesion Bieman and Ott introduced a measure of program cohesion using the following concepts from program and data slices: A data token is any variable or constant in the module A slice within a module is the collection of all the statements that can affect the value of some specific variable of interest. A data slice is the collection of all the data tokens in the slice that will affect the value of a specific variable of interest. Glue tokens are the data tokens in the module that lie in more than one data slice. Super glue tokens are the data tokens in the module that lie in every data slice of the program Measure Program Cohesion through 2 metrics: - weak functional cohesion = (# of glue tokens) / (total # of data tokens) - strong functional cohesion = (#of super glue tokens) / (total # of data tokens) Procedure Sum and Product (N : Integer; Var SumN, ProdN : Integer); Var I : Integer Begin SumN : = 0; ProdN : = ; For I : = to N do begin SumN : = SumN + I ProdN: = ProdN + I End; End; -2 6

Data Slice for SumN ( N : Integer; Var SumN, ProdN : Integer); Var I : Integer Begin SumN : = 0; ProdN : = ; For I : = to N do begin SumN : = SumN + I ProdN: = ProdN + I End; End; Data Slice for SumN = N SumN I SumN 2 0 I 2 2 N 2 SumN 3 SumN 4 I 3-3 Data Slice for ProdN ( N : Integer; Var SumN, ProdN : Integer); Var I : Integer Begin SumN : = 0; ProdN : = ; For I : = to N do begin SumN : = SumN + I ProdN: = ProdN + I End; End; Data Slice for ProdN = N ProdN I ProdN 2 I 2 2 N 2 ProdN 3 ProdN 4 I 4-4 7

Data token SumN ProdN N SumN ProdN I SumN 2 0 ProdN 2 I 2 2 N 2 SumN 3 SumN 4 I 3 ProdN 3 ProdN 4 I 4-5 Super Glue S S 2 S 3 I I I Super Glue I I I I I I Super Glue I I I Glue I I Glue -6 8

Functional Cohesion Strong functional cohesion (SFC) in this case is the same as WFC SFC = 5/7 = 0.204 If we had computed only SumN or ProdN then SFC = 7/7 = -7 Coupling Measure of the strength of inter-module connections High coupling indicates strong dependence between modules Should study modules as a pair Change to one module may ripple to the next Loose coupling indicates independent modules Generally we desire loose coupling, easier to comprehend and adapt 9

Types of Coupling. Content One module directly affects the workings of another Occurs when a module changes another module s data Generally should be avoided 2. Common Two modules have shared data, e.g. global variables 3. External Modules communicate through an external medium, like a file 4. Control One module directs the execution of another by passing control information (e.g. via flags) 5. Stamp Complete data structures or objects are passed from one module to another 6. Data Only simple data is passed between modules Modern Coupling Modern programming languages allow private, protected, public access Coupling may be modified to indicate levels of visibility, whether coupling is commutative Simple Interfaces generally desired Weak coupling and strong cohesion Communication between programmers simpler Correctness easier to derive Less likely that changes will propagate to other modules Reusability increased Comprehensibility increased 0

Dharma (995) Data and control flow coupling d i = number of input data parameters c i = number of input control parameters d o = number of output data parameters c o = number of output control parameters Global coupling g d = number of global variables used as data g c = number of global variables used as control Environmental coupling w = number of modules called (fan-out) r = number of modules calling the module under consideration (fan-in) -2 Coupling metric (m c ) m c = k/m, where k = Dharma (995) M = d i + a* c i + d o + b* c o + g d + c* g c + w + r where a=b=c=2 The more situations encountered, the greater the coupling, and the smaller m c One problem is parameters and calling counts don t guarantee the module is linked to the inner workings of other modules -22

High Level Strong Tight Coupling Cohesion Low Level Weak Loose Cohesion and Coupling Henry-Kafura (Fan-in and Fan-out) Henry and Kafura metric measures the inter-modular flow, which includes: Parameter passing Global variable access inputs outputs Fan-in : number of inter-modular flow into a program Fan-out: number of inter-modular flow out of a program Module, P Module s Complexity, Cp = ( fan-in x fan-out ) 2 for example above: Cp = (3 + ) 2 = 6 2

Information Hiding Each module has a secret that it hides from other modules Secret might be inner-workings of an algorithm Secret might be data structures By hiding the secret, changes do not permeate the module s boundary, thereby Decreasing the coupling between that module and its environment Increasing abstraction Increasing cohesion (the secret binds the parts of a module) Design involves a series of decisions. For each such decision, questions are: who needs to know about these decisions? And who can be kept in the dark? Complexity Complexity refers to attributes of software that affect the effort needed to construct or change a piece of software Internal attributes; need not execute the software to determine their values Many different metrics exist to measure complexity Two broad classes Intra-Modular attributes Inter-Modular attributes 3

Intra-Modular Complexity Two types of intra-modular attributes Size-Based Metrics E.g. Lines of Code Obvious objections but still commonly used Structure-Based Metrics E.g. complexity of control or data structures Halstead s Software Science Size-based metric Uses number of operators and operands in a piece of software n is the number of unique operators n 2 is the number of unique operands N is the total number of occurrences of operators N 2 is the total number of occurrences of operands Halstead derives various entities Size of Vocabulary: n = n +n 2 Program Length: N = N +N 2 Program Volume: V = Nlog 2 n Visualized as the number of bits it would take to encode the program being measured 4

Halstead s Software Science Potential Volume: V* = (2+n 2 )log(2+n 2 ) V* is the volume for the most compact representation for the algorithm, assuming only two operators: the name of the function and a grouping operator. n 2 is minimal number of operands. Program Level: L = V*/V Programming Effort: E = V/L Programming Time in Seconds: T = E/8 Numbers derived empirically, also based on speed human memory processes sensory input Halstead metrics really only measures the lexical complexity, rather than structural complexity of source code. Software Science Example. procedure sort(var x:array; n: integer) 2. var i,j,save:integer; 3. begin 4. for i:=2 to n do 5. for j:= to i do 6. if x[i]<x[j] then 7. begin save:=x[i]; 8. x[i]:=x[j]; 9. x[j]:=save 0. end. end 5

Software Science Example Operator # procedure sort() var 2 : 3 array ; 6 integer 2, 2 begin end 2 for..do 2 if then := 5 < [] 6 n=4 N=35 Operand # x 7 n 2 i 6 j 5 save 3 2 n2=7 N2=25 Size of vocabulary: 2 Program length: 60 Program volume: 264 Program level: 0.04 Programming effort: 6000 Estimated time: 333 seconds Structure-Based Complexity McCabe s Cyclomatic Complexity Create a directed graph depicting the control flow of the program CV = e n + 2p CV = Cyclomatic Complexity e = Edges n = nodes p = connected components 6

Cyclomatic Example For Sorting Code; numbers refer to line numbers 2 3 4 5 6 0 7 8 9 CV = 3 + 2* = 4 McCabe suggests an upper limit of 0 T.J. McCabe s Cyclomatic complexity metric is based on the belief that program quality is related to the complexity of the program control flow. Shortcomings of Complexity Metrics Not context-sensitive Any program with five if-statements has the same cyclomatic complexity Measure only a few facts; e.g. Halstead s method doesn t consider control flow complexity Others? Minix: Of the 277 modules, 34 have a CV > 0 Highest has 58; handles ASCII escape sequences. A review of the module was deemed justifiably complex ; attempts to reduce complexity by splitting into modules would increase difficulty to understand and artificially reduce the CV 7

System Structure Inter-Module Complexity The design may consist of modules and their relationships Can denote this in a graph; nodes are modules and edges are relationships between modules Types of inter-module relationships: Module A contains Module B Module A follows Module B Module A delivers data to Module B Module A uses Module B We are mostly interested in the last one, which manifests itself via a call graph Possible shapes: Chaotic Directed Acyclic Graph (Hierarchy) Layered Graph (Strict Hierarchy) Tree Module Hierarchies 8

Graph Metrics Metrics use: Size of the graph Depth Width (maximum number of nodes at some level) A tree-like call graph is considered the best design Some metrics measure the deviation from a tree; the tree impurity of the graph Compute number of edges that must be removed from the graph s minimum spanning tree Other metrics Complexity(M) = fanin(m)*fanout(m) Fanin/Fanout = local and global data flows Software Metrics Etiquette Use common sense and organizational sensitivity when interpreting metrics data. Provide regular feedback to the individuals and teams who have worked to collect measures and metrics. Don t use metrics to appraise individuals Work with practitioners and teams to set clear goals and metrics that will be used to achieve them. Never use metrics to threaten individuals or teams. Metrics data that indicate a problem area should not be considered negative. These data are merely an indicator for process improvement. Don t obsess on a single metric to the exclusion of other important metrics. -38 9