Program Slice Program slice was a concept first discussed by Mark Weiser in the early 1980’s –He especially noticed that when people debug, they trace.

Slides:



Advertisements
Similar presentations
Characterizing “Good” Design Besides the obvious design should match the requirements there are two “basic” characteristics: –Consistency across.
Advertisements

Advanced Programming 15 Feb The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Pfleeger and Atlee, Software Engineering: Theory and Practice CS499 Chapter 7 Writing the Programs Shari L. Pfleeger Joann M. Atlee 4 th Edition.
ECE 103 Engineering Programming Chapter 11 One Minute Synopsis Herbert G. Mayer, PSU CS Status 7/1/2014.
Dr. Yang, Qingxiong (with slides borrowed from Dr. Yuen, Joe) LT4: Control Flow - Loop CS2311 Computer Programming.
C# Console Application
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 5 Function Basics.
Software Engineering and Design Principles Chapter 1.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
Detailed Design Kenneth M. Anderson Lecture 21
Chapter 6 Horstmann Programs that make decisions: the IF command.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6: Odds and Ends  Formatted Output  Random numbers.
Instruction count for statements Methods Examples
Program Design and Development
Structured Program Development Dilshad M. Shahid New York
Algorithm Design CS105. Problem Solving Algorithm: set of unambiguous instructions to solve a problem – Breaking down a problem into a set of sub- problems.
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
CHAPTER 4: ALGORITHM 4.1 Introduction stages identified in the program development process: 1. Problem analysis and specification 2. Data organization.
Review Algorithm Analysis Problem Solving Space Complexity
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Data Flow Testing Data flow testing(DFT) is NOT directly related to the design diagrams of data-flow-diagrams(DFD). It is a form of structural testing.
CIS Computer Programming Logic
1 R. Johnsonbaugh, Discrete Mathematics Chapter 4 Algorithms.
Invitation to Computer Science, Java Version, Second Edition.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Lecture 4. RAM Model, Space and Time Complexity
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
By the end of this session you should be able to...
Software Design Design is the process of applying various techniques and principles for the purpose of defining a device, a process,, or a system in sufficient.
Algorithms An algorithm is an exact set of instructions for carrying out a task using a limited menu of commands Algorithms are most often associated with.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Lecture Notes - Copyright © S. C. Kothari, All rights reserved.1 Efficient Debugging CPRE 556 Lecture 19.
I Power Higher Computing Software Development High Level Language Constructs.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Arrays.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 3. Time Complexity Calculations.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
CS 108 Computing Fundamentals Notes for Thursday, February 18, 2016.
Control Structures: Examples. for-loop example Q: If a=1, b=3, and x=7, what is the value of x when the loop terminates? A: x=1 for(k=a; k
1 Week 7 Software Engineering Spring Term 2016 Marymount University School of Business Administration Professor Suydam.
Introduction to Computer Programming
School of Business Administration
CS1010 Programming Methodology
Design Characteristics and Metrics
What’s cheating and what is not?
Frank Tsui Software Engineering
Program Slicing Baishakhi Ray University of Virginia
Chapter 5 Function Basics
Subroutines and Functions
1) C program development 2) Selection structure
Chapter 7 Writing the Programs Shari L. Pfleeger Joann M. Atlee 4th Edition.
Arrays.
CSE 1020:Software Development
Chapter 8: Design: Characteristics and Metrics
Presentation transcript:

Program Slice Program slice was a concept first discussed by Mark Weiser in the early 1980’s –He especially noticed that when people debug, they trace a specific of interest variable backwards in the program to the point where the variable is defined (assigned a value) –This traced path is a condensed path of execution that allows us to check processing of that variable of interest.

A simple example of Program Slice Pseudo code example 1. int limit = 10; 2. int y = 0; 3. int x = 0; 4. for (int i = 0; i < limit ; i++) 5. {x = x + i; 6. y = y + i 2 ; } 7. print (“ x = “, x, “y =“, y); - Consider that our variable of interest is y at statement 7. - We would pick up statements: (because the loop influences statement 6) 2 1 (because limit influences statement 4) - Statements form a Program Slice - Note that: in executing just this slice, the value of y is the same at statement 7 as executing the whole example

Program Slice and Cohesion Besides, debugging, the notion of program slice also allow people to reduce the program to its “essentials” by looking at “key” variables. –e.g. the major output may be a key variable. This view allowed the possibility of looking at program cohesion through a set of program cohesion metrics.

Using Program and Data Slices to Measure Program Cohesion Bieman and Ott (early 1990’s) 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 program –A slice within a program 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 program that lie in more than one data slice. –Super glue tokens are the data tokens in the program 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)

A Pseudo-Code Example of Functional Cohesion Measure Finding the maximum and the minimum values procedure: MinMax ( z, n) Integer end, min, max, i ; end = n ; max = z[0] ; min = z[0] ; For ( i = 0, i = < end, i++ ) { if z[ i ] > max then max = z[ i ]; if z[ i ] < min then min = z[ i ]; } return max, min; Data Tokens: z1 n1 end1 min1 max1 i1 end2 n2 max2 z2 01 min2 z3 02 i2 03 i3 end3 i4 z4 i5 max3 max4 z5 i6 z6 i7 min3 min4 z7 i8 max5 min5 (33) Slice max: z1 n1 end1 max1 i1 end2 n2 max2 z2 01 i2 03 i3 end3 i4 z4 i5 max3 max4 z5 i6 max5 (22) Slice min: z1 n1 end1 min1 i1 end2 n2 min2 z3 02 i2 03 i3 end3 i4 z6 i7 min3 min4 z7 i8 min5 (22) Glue Tokens: z1 n1 end1 i1 end2 n2 i2 03 i3 end3 i4 (11) Super Glue: z1 n1 end1 i1 end2 n2 i2 03 i3 end3 i4 (11)

Example of pseudo-code Cohesion Metrics For the example of finding min and max, the glue tokens are the same as the super glue tokens. –Super glue tokens = 11 –Glue tokens = 11 The data slice for min and data slice for max turns out to be the same number, 22 The total number of data tokens is 33 The cohesion metrics for the example of min-max are: weak functional cohesion = 11 / 33 = 1/3 strong functional cohesion = 11 / 33 = 1/3 But, if we had only computed one function (e.g. only max), then : weak functional cohesion = 22 / 22 = 1 strong functional cohesion = 22/ 22 = 1 Note The change

Now look at the cohesion of the two earlier program samples - Are they “equally” cohesive based on Bieman and Ott metrics? - Perhaps it is coupling that we need to worry about ? - What type of coupling do you think this is?

Code Sample From Page Of Text For Tax problem tax = 0 if (taxable_income == 0) go to EXIT; if (taxable_income > 10000) tax = tax ; else { tax = tax +.10 * taxable_income; goto EXIT; } if (taxable_income > 20000) tax = tax ; else{ tax = tax +.12 * (taxable_income – 10000); goto EXIT; } if (taxable_income > 30000) tax = tax +1500; else{ tax = tax +.15 * (taxable_income – 20000); goto EXIT; } if (taxable_income < 40000) { tax = tax +.18 * (taxable_income – 30000); goto EXIT; } else tax = tax * (taxable_income – 40000); EXIT: ; 10% tax for the first $10,000 or less 12% tax for $10,001 to $20,000 15% tax for $20,001 to $30,000 18% tax for $30,001 to $39,999 20% tax for above $40,000 is this correct? See requirements

In Control Flow form Tax = 0.0 Inc= 0? Inc > 10k Tax = Tax + 1,000 Inc > 20k Tax = Tax + 1,200 Inc > 30k Tax = Tax + 1,500 Inc < 40k Tax = [Tax +.18(Inc -30k)] Tax = [Tax +1,800+.2(Inc -40k)] Tax = [Tax +.15(Inc -20k)] Tax = [Tax +.12(Inc -10k)] Tax = [Tax +.1(Inc ) ] Exit Cyclomatic complexity # = 5 +1 = 6 yes no yesno yesno yesno

Code sample from page 344 of text for same problem for (int i=2 ; level = 1; i <= 5; i++ ) { If (taxable_income > bracket [ i ] ) level = level + 1; else {tax = base [ level ] + percent [ level ] * (taxable_income – bracket [level] ) ; i = 6; } Tax table showing the bracket, base, and the percent columns bracket base percent Code structure is different because the algorithm is dependent on a table of Information, which may be implemented with 3 arrays e.g. float [ ] percent = {.10,.12,.15,.18,.20} and assume array indexing start with 1

In Control Flow form i=2 L =1 i = 6 L = L + 1 Tax = base[L] + ( percent[L] * (inc- bracket[L] )) i <=5 Exit Inc > bracket[i] i = i + 1 No Yes No Cyclomatic complexity # = = 3 With 3 defined arrays of: - base {0,10000, ---, 40,000} - bracket {0, 1000, - - -, 5500} - percent {.1,.12, - - -,.2}

Reuse After reviewing these two code examples, what do you think cohesion and coupling have to do with reuse? Did you not hear that highly cohesive and loosely coupled code is good for re-use? Which one do you think is more re-usable? If you are the reuse producer, would you do anything differently?