CSE403 ● Software engineering ● sp12 Week 7-10 MondayTuesdayWednesdayThursdayFriday Reading dueGroups Beta due SectionProgress report due Readings out.

Slides:



Advertisements
Similar presentations
Clean code. Motivation Total cost = the cost of developing + maintenance cost Maintenance cost = cost of understanding + cost of changes + cost of testing.
Advertisements

Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Software Engineering CSE470: Process 15 Software Engineering Phases Definition: What? Development: How? Maintenance: Managing change Umbrella Activities:
SOFTWARE MAINTENANCE 24 March 2013 William W. McMillan.
Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative to refactoring.
REFACTORING. What is refactoring ? In refactoring, you start with the basic code and make it better. Change the internal structure of the existing code.
Software Construction and Evolution - CSSE 375 Bad Smells in Code Shawn Bohner & Steve Chenoweth.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 4.0.
Design Patterns and Refactoring CSE 403. Outline Design Patterns Refactoring Refactoring patterns.
March 30, Exploratory Testing Testing Approaches Analytical Information-driven Intuitive Exploratory Design the tests and test concurrently Learn.
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
Xtreme Programming. Software Life Cycle The activities that take place between the time software program is first conceived and the time it is finally.
Software Development Models: Waterfall and Spiral Sung Hee Park Department of Mathematics and Computer Science Virginia State University August 21, 2012.
Test-Driven Development “Test first, develop later!” –OCUnit.
Chapter 9 – Software Evolution and Maintenance
SEG Software Maintenance1 Software Maintenance “The modification of a software product after delivery to correct faults, to improve performance or.
Maintenance Refactoring and Code Smells. Where are we? Over the semester we have talked about Software Engineering. The overall goal of software engineering.
1 CSE 403 Collaborative Programming: Pair Programming, Code Reviews, Walkthroughs and Maintenance and Refactoring These lecture slides are copyright (C)
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
Dillon: CSE470: SE, Process1 Software Engineering Phases l Definition: What? l Development: How? l Maintenance: Managing change l Umbrella Activities:
Design-Making Projects Work (Chapter7) n Large Projects u Design often distinct from analysis or coding u Project takes weeks, months or years to create.
Refactoring Cristescu Marilena. Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some.
© S. Demeyer, S. Ducasse, O. Nierstrasz Intro.1 1. Introduction Goals Why Reengineering ?  Lehman's Laws  Object-Oriented Legacy Typical Problems  common.
1 Collaborative Programming: Pair Programming and Reviews and Maintenance and Refactoring CSE 403.
COMP 208/214/215/216 Lecture 3 Planning. Planning is the key to a successful project It is doubly important when multiple people are involved Plans are.
Program Development Life Cycle (PDLC)
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
Rapid software development 1. Topics covered Agile methods Extreme programming Rapid application development Software prototyping 2.
Improving the Quality of Existing Code Svetlin Nakov Telerik Corporation
CSE403 ● Software engineering ● sp12 Week 7-10 MondayTuesdayWednesdayThursdayFriday Joel test & interviewing No reading GroupsReviewsSectionProgress report.
Refactoring1 Improving the structure of existing code.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
CSC 395 – Software Engineering Lecture 5: Teams -or- How to Motivate and Manage the Unwashed Masses.
©Ian Sommerville 2004 Software Engineering. Chapter 21Slide 1 Chapter 21 Software Evolution.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
Refactoring. Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
1 Software Maintenance and Evolution CSSE 575: Session 2, Part 1 Refactoring Principles Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring - 1 CS494: Intro. to Refactoring Readings: –Refactoring for everyone: How and why to use Eclipse's automated refactoring features. By David.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring. Mathematics: Factor ● fac·tor – One of two or more quantities that divides a given quantity without a remainder, e.g., 2 and 3 are factors.
CSE 403 Lecture 25 Scheduling and Planning a Large Project Reading: The Mythical Man-Month, Ch. 2, by F. Brooks slides created by Marty Stepp
Refactoring1 Improving the structure of existing code.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
1 COS 260 DAY 12 Tony Gauvin. 2 Agenda Questions? 5 th Mini quiz –Chapter 5 40 min Assignment 3 Due Assignment 4 will be posted later (next week) –If.
Integrating the Code during the Development Alexander Vakrilov Telerik Corporation
CSE403 ● Software engineering ● sp12 Week MondayTuesdayWednesdayThursdayFriday Midterm II reviewGroupsMidterm II [Notkin gone] No section Progress.
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.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 6.0.
Software Development. The Software Life Cycle Encompasses all activities from initial analysis until obsolescence Analysis of problem or request Analysis.
Implementation Topics Describe –Characteristics of good implementations –Best practices to achieve them Understand role of comments Learn debugging techniques.
Principles and examples
Software Development.
Software Metrics 1.
Reviewing Code A guide to smelling another developer’s source code.
Software Maintenance PPT By :Dr. R. Mall.
Refactoring and Code Smells
Objects First with Java
Code Smells 1.
Improving the structure of existing code
Refactoring and Code Smells
Refactoring and Code Smells
Introduction Software maintenance:
Chapter 9: Implementation
Refactoring and Code Smells
Presentation transcript:

CSE403 ● Software engineering ● sp12 Week 7-10 MondayTuesdayWednesdayThursdayFriday Reading dueGroups Beta due SectionProgress report due Readings out (see next slide) Midterm review GroupsMidterm II Reading covered [Notkin gone] No section Information on final presentations, etc. Course evals Progress report due Memorial Day Holiday GroupsFinal release due Project Pres. I Project Pres. II Project Pres. III CSE403 Sp121

Reading for Midterm II Managing Technical Debt Eric Allman Communications of the ACM Vol. 55 No. 5, Pages / CSE403 Sp122

Refactoring Belady and Lehman’s (1974) Law of Increasing Complexity –As a [software] system evolves its complexity increases unless work is done to maintain or reduce it In other words, it is natural for a program’s structure to degrade over time Work done “to maintain or reduce” the program’s complexity is not directly beneficial – it doesn’t make the program do more, do it more quickly, or such 3 CSE403 Sp12

Hence… Software system structures tend to degrade in practice Not only are they complex, but they are highly likely to be incidentally complex more than essentially complex [Brooks] CSE403 Sp124

Rewritten or abandoned As months pass and new versions are developed, many codebases reach one of the following states –rewritten: Nothing remains from the original code. –abandoned: The original code is thrown out and rewritten from scratch. –…even if the code was initially reviewed and well- designed at the time of check-in, and even if check-ins are reviewed CSE403 Sp12

“Bit rot” Why does the code structure degrade? –Systems evolve to meet new needs and add new features –If the code's structure does not also evolve, it will “rot” –And the value-proposition for maintaining or improving the code structure is hard to see and evaluate CSE403 Sp126

Maintenance Modification of a software product after delivery –fix bugs –improve performance –improve design –add features ~80% of maintenance is for non-bug-fix-related activities such as adding functionality (Pigosky 1997) CSE403 Sp12

Maintenance is hard It's harder to maintain code than write new code –must understand code written by another developer, or code you wrote at a different time with a different mindset –danger of errors in fragile, poorly-understood code (don't touch it!) Maintenance is how devs spend most of their time –Many developers hate code maintenance. Why? With good design and advance planning, maintenance is less painful –Capacity for future change must be anticipated Q: If maintenance is harder than writing new code, why is it assigned more frequently to newbies? CSE403 Sp12

Refactoring Improving a piece of software's internal structure without altering its external behavior –Incurs a short-term time/work cost to reap long- term benefits –A long-term investment in the overall quality of your system refactoring is not the same thing as –rewriting code –adding features –debugging code CSE403 Sp12

Why refactor? Each part of your code has three purposes –to execute its functionality, –to allow change, –to communicate well to developers who read it Code that is weak in any of these dimensions can be improved Refactoring improves software's design –more extensible, flexible, understandable, faster, … –Every design improvement has costs (and risks)

Code “smells”: Signs you should refactor Duplicated code Poor abstraction (change one place → must change others) Large loop, method, class, parameter list; deeply nested loop Module has too little cohesion Modules have too much coupling Module has poor encapsulation A “middle man” object doesn't do much (e.g., a “weak subclass” doesn’t use inherited functionality) Dead code Design is unnecessarily general Design is too specific CSE403 Sp1211

CSE403 Sp12 Low-level refactoring Names –Renaming (methods, variables) –Naming (extracting) “magic” constants Procedures –Extracting code into a method –Extracting common functionality (including duplicate code) into a module/method/etc. –Inlining a method/procedure –Changing method signatures Reordering: –Splitting one method into several to improve cohesion and readability (by reducing its size) –Putting statements that semantically belong together near each other

CSE403 Sp12 IDE support for refactoring 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

Higher-level refactoring Refactoring to design patterns Exchanging risky language idioms with safer alternatives Performance optimization Clarifying a statement that has evolved over time or is unclear Compared to low-level refactoring, high-level is –Not as well-supported by tools –Much more important! CSE403 Sp12

Recommended refactor plan When you identify an area of your system that –is poorly designed –is poorly tested, but seems to work so far –now needs new features What should you do? –Write unit tests that verify the code's external correctness They should pass on the current, badly designed code –Refactor the code. Some unit tests may break. Fix the bugs –Add the new features –As always, keep changes small, do code reviews, etc. CSE403 Sp12

“I don't have time to refactor!” Refactoring incurs an up-front cost. –some developers don't want to do it –most management don't like it, because they lose time and gain “nothing” (no new features) However... –well-written code is much more conducive to rapid development (some estimates put ROI at 500% or more for well-done code) –finishing refactoring increases programmer morale developers prefer working in a “clean house” When to refactor? –best done continuously (like testing) as part of the SE process –hard to do well late in a project (like testing) Why? CSE403 Sp12

Should startups refactor? Many small companies and startups skip refactoring –“We're too small to need it!” –“We can't afford it!” Reality –Refactoring is an investment in quality of the company's product and code base, often their prime assets –Many web startups are using the most cutting-edge technologies, which evolve rapidly. So should the code –If a key team member leaves (common in startups),... –If a new team member joins (also common),...

Refactoring: reprise “Improving a piece of software's internal structure without altering its external behavior” What does “without altering its external behavior” mean? How can we tell if a refactoring has left the behavior unchanged? Do we care? CSE403 Sp1218