Program Refactoring Mitch Soden Union College. Agenda Definition –Unit Testing –Examples Why Refactor? Limitations Just Another SW Eng Practice? Automation.

Slides:



Advertisements
Similar presentations
Requirements for a UI Test Framework Stanislaw Wozniak Bernie Miles.
Advertisements

Revealing the Secrets of Self-Documenting Code Svetlin Nakov Telerik Corporation For C# Developers.
Chapter 16 Exception Handling. What is Exception Handling? A method of handling errors that informs the user of the problem and prevents the program from.
Clean code. Motivation Total cost = the cost of developing + maintenance cost Maintenance cost = cost of understanding + cost of changes + cost of testing.
A practical guide John E. Boal TestDrivenDeveloper.com.
Sommerville, I., Software Engineering, Pearson, 9th Ed., 2010.
1 Software Maintenance and Evolution CSSE 575: Session 2, Part 2 Composing Methods Steve Chenoweth Office Phone: (812) Cell: (937)
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
George Blank University Lecturer. REFACTORING Improving the Design of Existing Code Supplement to Ian Sommerville, Software Engineering, Chapter 20 Prepared.
Well-behaved objects Improving your coding skills 1.0.
SOS OOP Fall 2001 Object Oriented Programming in Java Week 1 Read a design Design a small program Extract a design Run a VAJ program Change that program,
CSE 219 COMPUTER SCIENCE III PROPERTIES OF HIGH QUALITY SOFTWARE.
UML and Object Oriented Concepts
CASE Tools And Their Effect On Software Quality Peter Geddis – pxg07u.
Cyclomatic Complexity Dan Fleck Fall 2009 Dan Fleck Fall 2009.
Maintenance Refactoring and Code Smells. Where are we? Over the semester we have talked about Software Engineering. The overall goal of software engineering.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
© 2012 IBM Corporation Rational Insight | Back to Basis Series Chao Zhang Unit Testing.
Project Tracking. Questions... Why should we track a project that is underway? What aspects of a project need tracking?
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
The Java Programming Language
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.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
Small changes to code to improve it. Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Inoue Laboratory Eunjong Choi 1 Investigating Clone.
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
Refactoring1 Improving the structure of existing code.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Elucidative Programming Kurt Nørmark Aalborg University Denmark SIGDOC September 2000.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
Cmpe 589 Spring 2006 Lecture 2. Software Engineering Definition –A strategy for producing high quality software.
Teaching material for a course in Software Project Management & Software Engineering – part V.
Writing Maintainable code Dr. Susan McKeever DT228/3 GUI Programming.
Reduce Development and Testing Time on Embedded Space Programs With Auto- Generated Code Software Engineer Northrop Grumman Electronic Systems Matthew.
Software Construction and Evolution - CSSE 375 Making Method Calls Simpler Shawn and Steve Below – “Be the character!” The late acting teacher Lee Strasberg.
Page 1 – Autumn 2009Steffen Vissing Andersen SDJ I1, Autumn 2009 Agenda: Java API Documentation Code Documenting (in javadoc format) Debugging.
Refactoring Advanced Software Engineering Dr Nuha El-Khalili.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
Process Asad Ur Rehman Chief Technology Officer Feditec Enterprise.
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.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
Refactoring. DCS – SWC 2 Refactoring ”A change made to the internal structure of software to make it easier to understand and cheaper to modify without.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
ING XBRL Proof of Concept July 19, ©2005 page 2. Utilizing XBRL  ING Objectives  Benefits  Goals  Proof of Concept Plan  Stat  USGAAP  Pain.
Code Refactoring Milan Vukoje Soprex SkfOffice2 SkfOffice3 Big5 Quality oriented We are hiring…
ICONFINDER ICONFINDER Founded Django based web application -PostgreSQL -Elasticsearch -Amazon Elastic Compute.
Refactoring Presentation Yash Pant. Overview 3 Refactoring Types: 1. Replace Error Code with Exception 2. Split Temporary Variable 3. Remove Middle Man.
A (Very) Simple Example Consolidate duplicate conditional fragments if (isSpecialDeal()) { total = price * 0.95; send (); } else { total = price * 0.98;
Software Metrics 1.
Prototyping Lecture # 08.
COS 260 DAY 17 Tony Gauvin.
EE422C Software Implementation II
Software Construction and Evolution - CSSE 375 Composing Methods
Cyclomatic Complexity
Introduction to Software Testing
Subprograms and Programmer Defined Data Type
Cyclomatic Complexity
CSSSPEC6 SOFTWARE DEVELOPMENT WITH QUALITY ASSURANCE
Week 6 Object-Oriented Programming (2): Polymorphism
COS 260 DAY 16 Tony Gauvin.
Scheduling Academic Groundwork Assistance
Test Driven Lasse Koskela Chapter 9: Acceptance TDD Explained
Improving the structure of existing code
Refactoring Support Tool: Cancer
Refactoring.
Ninth step for Learning C++ Programming
Tenth step for Learning C++ Programming
Requirements Engineering
Presentation transcript:

Program Refactoring Mitch Soden Union College

Agenda Definition –Unit Testing –Examples Why Refactor? Limitations Just Another SW Eng Practice? Automation tools

Definition Controlled/deliberate process Improve design/internal structure Existing code Behavior-preserving

Unit Testing Solid test suite - 1 st step in refactoring Test after each refactoring Should be automated & self-checking Focus tests based on risk

Example – Extract Method Make code fragment into method whose name explains the purpose.... // print banner System.out.println (“*********************”); System.out.println (“*** Customer Info ***”); System.out.println (“*********************”); // perform calculations while (x.hasMoreElements()) {... } // print details System.out.println (“Name: ” + name); System.out.println (“Balance: ” + balance);

Example – Extract Method Refactored code:... printBanner(); // perform calculations while (x.hasMoreElements()) {... } printDetails(balance); } void printBanner() { System.out.println (“*********************”); System.out.println (“*** Customer Info ***”); System.out.println (“*********************”); } void printDetails(double balance) {...

Example – Replace Error Code with Exception Make a method throw an exception instead of returning a special code to indicate an error. int withdraw(int amount) { if (amount > _balance) return –1; else { _balance -= amount; return 0; }

Example – Replace Error Code with Exception Refactored code: void withdraw(int amount) throws BalanceException { if (amount > _balance) throw new BalanceException(); _balance -= amount; }

Why Refactor? Problems Software modifications degrade structure Maintenance costs too high Inability to meet schedules

Why Refactor? Refactoring helps by Making software easier to understand Making software cheaper to modify Allowing developers become more productive

Limitations/Drawbacks Time Human factor Changing interfaces Non-object oriented languages

Just Another Software Engineering Practice? Immediate payback Personal benefits It feels good

Automation Tools Refactoring Browser –1 st refactoring tool built –Univ. of Illinois PhD work –Supports Smalltalk –Integrates w/ Smalltalk Browser

Automation Tools RefactorIt –Aqris Software, 2002 –Integrates w/ JBuilder, Forte, JDeveloper –Many common refactorings –Includes code metrics –Automates auditing and corrective actions

Questions, comments, opinions?