09 Aug 2006CSE403 Summer'06 Lecture 19b Lecture 19: Software Quality (Part II) Valentin Razmov Conway’s Law: “The structure of a computer program reflects.

Slides:



Advertisements
Similar presentations
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Advertisements

Software Engineering CSE470: Process 15 Software Engineering Phases Definition: What? Development: How? Maintenance: Managing change Umbrella Activities:
CS 3500 SE - 1 Software Engineering: It’s Much More Than Programming! Sources: “Software Engineering: A Practitioner’s Approach - Fourth Edition” Pressman,
Applied Software Project Management Andrew Stellman & Jennifer Greenehttp:// Applied Software Project Management Introduction.
12 Aug 2005CSE403, Summer'05, Lecture 15 Updated Schedule of Remaining Class-Related Deliverables Fri, Aug 10pm: hw#4 responses due Sun, Aug
Chapter 15 Design, Coding, and Testing. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Design Document The next step in the Software.
Design Patterns and Refactoring CSE 403. Outline Design Patterns Refactoring Refactoring patterns.
R R R CSE870: Advanced Software Engineering (Cheng): Intro to Software Engineering1 Advanced Software Engineering Dr. Cheng Overview of Software Engineering.
Applied Software Project Management Andrew Stellman & Jennifer Greene Applied Software Project Management Applied Software.
Computer Engineering 203 R Smith Agile Development 1/ Agile Methods What are Agile Methods? – Extreme Programming is the best known example – SCRUM.
CSE1301 Computer Programming: Lecture 13 Documentation.
1 Jul 2005CSE403, Summer'05, Section 02 Section 02: Life Cycle Architecture Review Valentin Razmov.
Applied Software Project Management Andrew Stellman & Jennifer Greene Applied Software Project Management Applied Software.
Applied Software Project Management 1 Introduction Dr. Mengxia Zhu Computer Science Department Southern Illinois University Carbondale.
Xtreme Programming. Software Life Cycle The activities that take place between the time software program is first conceived and the time it is finally.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
CODING Research Data Management. Research Data Management Coding When writing software or analytical code it is important that others and your future.
Test-Driven Development “Test first, develop later!” –OCUnit.
13 Jul 2006CSE403, Summer'06, Lecture10 Lifecycle Architecture Review: Preliminary Feedback Valentin Razmov.
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
1 CSE 403 Collaborative Programming: Pair Programming, Code Reviews, Walkthroughs and Maintenance and Refactoring These lecture slides are copyright (C)
Test Driven Development An approach to writing better code Jimmy Zimmerman Intel Corporation.
Applied Software Project Management Andrew Stellman & Jennifer Greene Applied Software Project Management greene.com 1 Applied Software.
Applied Software Project Management Andrew Stellman & Jennifer Greenehttp:// Applied Software Project Management Chapter 1: Introduction.
Dillon: CSE470: SE, Process1 Software Engineering Phases l Definition: What? l Development: How? l Maintenance: Managing change l Umbrella Activities:
CSE G674/2009 Project Project Management Section Presented by: Amir Aref Adib.
Object Oriented Analysis and Design Introduction.
Understand Application Lifecycle Management
Teaching material for a course in Software Project Management & Software Engineering – part II.
1 Collaborative Programming: Pair Programming and Reviews and Maintenance and Refactoring CSE 403.
Design and Programming Chapter 7 Applied Software Project Management, Stellman & Greene See also:
Extreme/Agile Programming Prabhaker Mateti. ACK These slides are collected from many authors along with a few of mine. Many thanks to all these authors.
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
1 ENERGY 211 / CME 211 Lecture 26 November 19, 2008.
CSE403 ● Software engineering ● sp12 Week 7-10 MondayTuesdayWednesdayThursdayFriday Reading dueGroups Beta due SectionProgress report due Readings out.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Refactoring1 Improving the structure of existing code.
(c) University of Washington01-1 CSC 143 Java Programming as Modeling Reading: Ch. 1-6.
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
Chapter 7 The Practices: dX. 2 Outline Iterative Development Iterative Development Planning Planning Organizing the Iterations into Management Phases.
11 Jul 2005CSE403, Summer'05, Lecture 08 Lecture 08: Best Practices for Software Design (Part I) Valentin Razmov.
Requirements Engineering Requirements Engineering in Agile Methods Lecture-28.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
09 Mar 2007CSE403 Winter '07 What Happens after a Product Ships? Valentin Razmov (guest lecture) Special guest: Jim Bullock (Rare Bird Enterprises)
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
07 Jul 2006CSE403, Summer'06, Lecture10 Lecture 10: Core Principles and Best Practices for Software Design (Part I) “Treat design as a wicked, sloppy,
CS223: Software Engineering Lecture 18: The XP. Recap Introduction to Agile Methodology Customer centric approach Issues of Agile methodology Where to.
Deliverables: Zero-Feature Release Build process, installation process, code repository, automated testing framework, bug tracking system Maybe no tests.
Software Design and Development Development Methodoligies Computing Science.
INTRODUCTION CSE 470 : Software Engineering. Goals of Software Engineering To produce software that is absolutely correct. To produce software with minimum.
Software Development. The Software Life Cycle Encompasses all activities from initial analysis until obsolescence Analysis of problem or request Analysis.
14 Jul 2005CSE403, Summer'05, Lecture 09 Lecture 09: Fundamental Principles and Best Practices for Software Design Valentin Razmov.
Coming up: What is Agile? XP Development Dan Fleck 2010 Dan Fleck 2010.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
02 Feb 2006CSE481B, Winter'06, Lecture 10 Announcements Tuesday, Feb 07 – no class Use it to work on your milestone release Thursday, Feb 09 – project.
Advanced Software Engineering Dr. Cheng
Principles and examples
Module Road Map Refactoring Why Refactoring? Examples
Managing the Project Lifecycle
Best Practices for Software System Design
Objects First with Java
Overview of Eclipse Lectures
Design and Programming
Improving the structure of existing code
Updated Schedule of Remaining Class-Related Deliverables
CSE 303 Concepts and Tools for Software Development
Beginning Style 27-Feb-19.
Presentation transcript:

09 Aug 2006CSE403 Summer'06 Lecture 19b Lecture 19: Software Quality (Part II) Valentin Razmov Conway’s Law: “The structure of a computer program reflects the structure of the organization that built it.”

09 Aug 2006CSE403 Summer'06 Lecture 19b Outline Quality – a look back at history “Good enough” quality What is (software) quality? How do we measure quality? How do we improve software quality? Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 19b Components of Quality (discussed previously) Quality comprises (but is not limited to): Requirements quality Design quality Code quality Test quality Documentation quality Given limited resources, which of these do you consider more important to pay attention to? Why? Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 19b How Do We Measure Software Quality? Software is never perfect. We can test it, but… Fundamentally, we can not ensure it is free of defects. What can be done to assess the quality then? Many engineering disciplines use standards for quality. In software, there are few standards, and all (viable) ones assess the quality of processes, not products. Most non-trivial properties of software (code) cannot be inferred or verified, because of the Halting Problem. We are forced to link process quality to product quality. Conway’s Law: “The structure of a computer program reflects the structure of the organization that built it.” E.g.: CMM (Capability Maturity Model) assesses the quality of teams/organizations through their processes. Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 19b Mechanisms for Raising the Quality of Software Assume you are brought in on an ongoing software project plagued by poor quality. What one or two approaches (mechanisms) would you propose to help raise the quality of the software in production? Make assumptions as needed, to concretize the question. Student Submission Valentin Razmov ----

09 Aug 2006CSE403 Summer'06 Lecture 19b Mechanisms for Raising the Quality of Software: Some Ideas Which of the following mechanisms do you use (or plan to use) on your project? Circle all that apply. a) Involvement / frequent iterations with customers and other stakeholders b) Pair programming c) Code reviews (not limited to “code”; requirements/design review, etc.) d) External auditing e) Using automated tools (e.g., static analysis, code coverage, IDEs, etc.) to help discover non-trivial properties that affect quality f) Refactoring g) Code integration (if not already in place) h) Testing: integration testing, regression testing, acceptance testing; automated testing; test-driven development (with unit testing) i) Component reuse j) Team building activities k) Establish (or ensure the presence of) clear responsibilities within the team l) Realistic up-to-date scheduling Student Submission Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 19b Recipes for Creating Disasters (a.k.a. Poor Quality Products) Ignore what the customers say they want – the developers surely must know better. Put in all the features that could potentially ever be useful. Do not worry about quality aspects (and ignore the related practices) until the deadline approaches. Do not waste time on design or documentation – after all, code is the most important thing and time is already too short to do all that needs to be done. … Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Lecture 20: Refactoring Question: Is there anything wrong with this code? char b[2][10000],*s,*t=b,*d,*e=b+1,**p;main(int c,char**v) {int n=atoi(v[1]);strcpy(b,v[2]);while(n--){for(s=t,d=e;*s;s++) {for(p=v+3;*p;p++)if(**p==*s){strcpy(d,*p+2);d+=strlen(d); goto x;}*d++=*s;x:}s=t;t=e;e=s;*d++=0;}puts(t);} Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Outline Motivation and definition of refactoring Playing with real code examples Main refactoring strategies When refactoring works and when it does not Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 References Recommended: Refactoring resources online, by Martin Fowler, Other relevant resources: Applied Software Project Management, by Andrew Stellman and Jennifer Greene, Writing Solid Code, by Steve Maguire, Agile Software Development: Principles, Patterns, and Practices, by Robert Martin, Professional Software Development, by Steve McConnell, Sustainable Software Development – An Agile Perspective, by Kevin Tate, Freakonomics: A Rogue Economist Explores the Hidden Side of Everything, by Steven Levitt and Stephen Dubner, Design Patterns Explained, by Alan Shalloway and James Trott, Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Motivating Question Many software products get completely rewritten or abandoned after a few versions and/or several years. What might be causing this? Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Motivating Question (cont.) Many software products get completely rewritten or abandoned after a few versions and/or several years. One possible (and correct) cause is: Code evolves to meet evolving business needs and developer understanding. If its structure does not evolve too, it will deteriorate (“rot”) over time, becoming increasingly hard to maintain and extend. Related terms: “code rot”, “spaghetti code” Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 More Motivation Case: Imagine you’ve written a piece of code but accidentally deleted and lost it. Questions:  How much time would it take you to reconstruct from scratch what you had – the same amount, or more, or less?  Would the code have a better design the second time you write it? Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 More Motivation (cont.) Software is an intellectual product, not a routine one, so the process of its creation necessarily goes through revisions. If this were not the case: … the programming task could (and should!) be automated… … and the programmers might need to find more interesting (and less routine) jobs. Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Putting the Evidence Together Fact: Code evolves Contrary to the popular myth, most software projects can not be first designed, then coded, then tested... This waterfall lifecycle model does not work well for most software projects. Therefore: (Evolving) code needs to be maintained to keep it from becoming a mess. Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Refactoring Defined “[Refactoring is] the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure.” -- Martin Fowler Note: Refactoring is not the same as code rewriting; it is more disciplined and structured (as we will see).  What is the “opposite” of refactoring?  Why might one want to do that? Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Refactoring – Why Do It? Why is it necessary? A long-term investment in the quality of the code and its structure Code structure deteriorates when last-minute fixes are made or unplanned features are added. Doing no refactoring may save costs / time in the short term but pays a huge interest in the long run “Don’t be penny-wise but hour-foolish!” Why fix it if it ain’t broken? Every module has three functions: (a) to execute according to its purpose; (b) to afford change; (c) to communicate to its readers. It it does not do one or more of these, it is broken. Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Examples of What We Don’t Want to Have to Maintain 1) q = ((p<=1) ? (p ? 0 : 1) : (p==-4) ? 2 : (p+1)); 2) while (*a++ = *b--) ; 3) char b[2][10000],*s,*t=b,*d,*e=b+1,**p;main(int c,char**v) {int n=atoi(v[1]);strcpy(b,v[2]);while(n--){for(s=t,d=e;*s;s++) {for(p=v+3;*p;p++)if(**p==*s){strcpy(d,*p+2);d+=strlen(d); goto x;}*d++=*s;x:}s=t;t=e;e=s;*d++=0;}puts(t);} Hint: Can each of them: (a) execute according to its purpose? (b) afford change? (c) communicate to its readers? What is common among the following examples? Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 The Issue of Style If you have been a TA or consultant for a programming course, or if you have tutored beginning programmers or just curious friends… How have you explained to them why style mattered: meaningful variable names naming constants standard indentation etc. even if the code still worked as desired? Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Let’s Do Some Refactoring! Valentin Razmov

class Account { float principal, rate; int daysActive, accountType; public static final int STANDARD = 0; public static final int BUDGET = 1; public static final int PREMIUM = 2; public static final int PREMIUM_PLUS = 3; } float calculateFee(Account accounts[]) { float totalFee = 0; Account account; for (int i=0; i<accounts.length; i++) { account = accounts[i]; if ( account.accountType == Account.PREMIUM || account.accountType == Account.PREMIUM_PLUS ) { totalFee +=.0125 * ( account.principal * Math.exp( account.rate * (account.daysActive/365.25) ) - account.principal ); } return totalFee; } Student Submission Activity: Circle the aspects that need to be refactored and briefly state how you would improve those.

float interestEarned() { float years = daysActive / (float) ; float compoundInterest = principal * (float) Math.exp( rate * years ); return ( compoundInterest – principal ); } float isPremium() { if (accountType == Account.PREMIUM || accountType == Account.PREMIUM_PLUS) return true; else return false; } float calculateFee(Account accounts[]) { float totalFee = 0; Account account; for (int i=0; i<accounts.length; i++) { account = accounts[i]; if ( account.isPremium() ) totalFee += BROKER_FEE_PERCENT * account.interestEarned(); } return totalFee; } static final double BROKER_FEE_PERCENT = ; The author’s refactored code (excerpt from “Applied Software Project Management”)

09 Aug 2006CSE403 Summer'06 Lecture 20 Types of Refactoring Refactoring to patterns Renaming (methods, variables) Extracting code into a method Changing method signatures Performance optimization Naming (extracting) “magic” constants Extracting common functionality (including duplicate code) into a service / module / class / method Splitting one method into several to improve cohesion and readability (by reducing its size) Putting statements that semantically belong together near each other Exchanging risky language idioms with safer alternatives Clarifying a statement (that has evolved over time and/or that is hard to “decipher”) Valentin Razmov

09 Aug 2006CSE403 Summer'06 Lecture 20 Language and Tool Support for Refactoring Modern IDEs (e.g., Eclipse, Visual Studio) support: variable / method / class renaming method or constant extraction extraction of redundant code snippets method signature change extraction of an interface from a type method inlining providing warnings about method invocations with inconsistent parameters help with self-documenting code through auto-completion Older development environments (e.g., vi, Emacs, etc.) have little or no support for these. Discourages programmers from refactoring their code Valentin Razmov