Advanced Programing practices

Slides:



Advertisements
Similar presentations
Module 7. Simplifying Conditional Expressions Course: Refactoring.
Advertisements

A Brief Introduction to Test- Driven Development Shawn M. Jones.
You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting
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 By: Brian Smith. What is Refactoring? Definition: a change to the internal structure of software to make it easier to understand and cheaper.
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.
XP and Refactoring David Talby. Development Methodologies The Software Crisis – 84% of software projects are not on time – 31% of software projects never.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES Introduction.
Chapter 9 – Software Evolution and Maintenance
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES API documentation.
Maintenance Refactoring and Code Smells. Where are we? Over the semester we have talked about Software Engineering. The overall goal of software engineering.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Unit Testing.
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Refactoring Cristescu Marilena. Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some.
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
© ALEXANDRE CUVA  VERSION 2.00 Test Driven Design.
11 Partnership for Performance How to hear this lecture Click on the icon: to hear the narration for each slide.
17-Oct-15 Refactoring. 2 Refactoring is: restructuring (rearranging) code......in a series of small, semantics-preserving transformations (i.e. the code.
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.
Refactoring1 Refactoring DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY February 6, 2009.
SWE 316: Software Design and Architecture Objectives Lecture # 20 Improving the existing design: Refactoring SWE 316: Software Design and Architecture.
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 1 Simplifying Conditionals Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring1 Improving the structure of existing code.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES Code quality.
Alcatel-Lucent CDC Workshop, Coaching & Knowledge Transfer Coding.
Advanced Programming in Java
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAM DESIGN WITH C++ Part 9:
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 1 Towards an Assessment of the Quality of Refactoring.
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.
Refactoring. Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
NJIT 1 Test Driven Development and Refactoring Larman, Chapter 21.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Com S 362: Object-Oriented Analysis and Design Refactoring.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Software Construction and Evolution - CSSE 375 Making Method Calls Simpler Shawn and Steve Below – “Be the character!” The late acting teacher Lee Strasberg.
1 ECE 750 Topic 8 Meta-programming languages, systems, and applications Evolving Object-Oriented Designs with Refactorings – Lance Tokuda and Don Batory.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
Refactoring Mehdi Einali Advanced Programming in Java 1.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring Advanced Software Engineering Dr Nuha El-Khalili.
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.
Refactoring1 Improving the structure of existing code.
Refactoring. 2 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.
Software Construction and Evolution - CSSE 375 Simplifying Conditionals Shawn & Steve.
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.
Code Refactoring Milan Vukoje Soprex SkfOffice2 SkfOffice3 Big5 Quality oriented We are hiring…
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Realizing quality improvement through test driven development: Results and experiences of four industrial teams. by Nachiappan Nagappan, E Mchael Maximillien,
Principles and examples
Refactoring Refactoring.
Module Road Map Refactoring Why Refactoring? Examples
Advanced Programming in Java
Refactoring SENG 301 © Refactoring: Improving the Design of Existing Code, Martin Fowler, Kent Beck Source:
Refactoring and Code Smells
بازآرایی برنامه Code Refactoring
Overview of Eclipse Lectures
Improving the structure of existing code
Refactoring and Code Smells
Advanced Programming Behnam Hatami Fall 2017.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Refactoring and Code Smells
Advanced Programing practices
Refactoring and Code Smells
Presentation transcript:

Advanced Programing practices SOEN 6441 - Advanced Programming Practices Advanced Programing practices Refactoring Joey Paquet, 2006-2014

Refactoring: what is it? SOEN 6441 - Advanced Programming Practices Refactoring: what is it? Definition: Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Refactoring does not fix bugs, but it may help find bugs by scrutinizing code. It may also reduce the further introduction of bugs by cleaning-up code. Refactoring does not add new functionality to the system, but it will ease the further adding of new functionality. It is an essential part of agile software development such as Extreme Programming or incremental development. Joey Paquet, 2006-2014

SOEN 6441 - Advanced Programming Practices Refactoring: when? Refactoring ought to be done continuously as “bad smells” are encountered during programming. “Bad smells” or “anti-patterns” are portions of design or code that are characterized as potentially confusing and identifies as refactoring targets. More importantly, when using iterative development, a major refactoring stage should precede the beginning of the development of a new build. This will remove slight design problems and ease the addition of further functionality. In this case, refactoring counterbalances the productivity-driven software development practices implied by agile incremental software development. Joey Paquet, 2006-2014

Refactoring is usually done to: SOEN 6441 - Advanced Programming Practices Refactoring: why? Refactoring is usually done to: Improve quality improve design quality improve maintainability improve extensibility Improve sustainability of development requires proper testing, so improves testability helps to find bugs Improve productivity improve code readability & comprehensibility simplify code structure Joey Paquet, 2006-2014

Refactoring process: test-refactor-test SOEN 6441 - Advanced Programming Practices Refactoring: how? Each refactoring is implemented as a small behavior-preserving transformation. Behavior-preservation is achieved through pre- and post-transformation testing. Refactoring process: test-refactor-test Joey Paquet, 2006-2014

Refactoring: drawbacks SOEN 6441 - Advanced Programming Practices Refactoring: drawbacks Cost Overhead: Refactoring is an add-on activity and therefore will incur extra cost in form of time, effort, and resource allocation, especially if elaborated design and code documentation is maintained. However, when done sparingly and only on key issues, its benefits are greater than its overhead. Automated documentation tools, code browsing tools, refactoring tools and testing tools will also diminish the refactoring overhead. Requires Expertise: Refactoring requires some expertise and experience and considerable effort in going through the process, especially if proper testing is involved. However, this overhead can be minimized by using refactoring tools and automated testing such as with a unit testing framework. Joey Paquet, 2006-2014

Refactoring patterns SOEN 6441 - Advanced Programming Practices Joey Paquet, 2006-2014

Reractoring: examples SOEN 6441 - Advanced Programming Practices Reractoring: examples Encapsulate Downcast: A method returns an object that needs to be downcasted by its callers. Refactor by moving the downcast to within the method. Object lastReading() { return readings.lastElement(); } Reading lastReading() { return (Reading) readings.lastElement(); } Joey Paquet, 2006-2014

Refactoring: examples SOEN 6441 - Advanced Programming Practices Refactoring: examples Consolidate Conditional Expression: You have a sequence of conditional tests with the same result. Refactor by combining them into a single conditional expression and extract it. double disabilityAmount() { if (_seniority < 2) return 0; if (_monthsDisabled > 12) return 0; if (_isPartTime) return 0; // compute the disability amount double disabilityAmount() { if (isNotEligibleForDisability()) return 0; // compute the disability amount Joey Paquet, 2006-2014

Refactoring: examples SOEN 6441 - Advanced Programming Practices Refactoring: examples Consolidate Duplicate Conditional Fragments: The same fragment of code is in all branches of a conditional expression. Refactor by moving it outside of the expression. if (isSpecialDeal()) { total = price * 0.95; send(); } else { total = price * 0.98; } if (isSpecialDeal()) total = price * 0.95; else total = price * 0.98; send(); Joey Paquet, 2006-2014

Refactoring: examples SOEN 6441 - Advanced Programming Practices Refactoring: examples Rename Method: The name of a method does not reveal its purpose. Refactor it by changing the name of the method. int getInvCdtLmt(){ … } int getInvoiceableCreditLimit(){ … } Joey Paquet, 2006-2014

Refactoring: examples SOEN 6441 - Advanced Programming Practices Refactoring: examples Pull Up Field: Two subclasses have the same field. Refactor it by moving the field to the superclass. Joey Paquet, 2006-2014

Refactoring: examples SOEN 6441 - Advanced Programming Practices Refactoring: examples Push Down Method: Behavior on a superclass is relevant only for some of its subclasses. Refactor it by moving it to those subclasses. Joey Paquet, 2006-2014

Refactoring: practice SOEN 6441 - Advanced Programming Practices Refactoring: practice Some refactorings are controversial. Some refactorings are arguably not improving code quality. Some refactorings can in fact be counter-productive when applied blindly, especially in iterative development, where design is evolving. Have your team adopt a set of refactorings to be applied, and make sure that refactorings are applied in a productive manner. Apply in combination with the application of design patterns. Use refactoring tools to automate changes, e.g. Eclipse refactoring, and JUnit testing framework. Joey Paquet, 2006-2014

SOEN 6441 - Advanced Programming Practices References Source Making. Refactoring. http://sourcemaking.com/refactoring Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts. Refactoring: Improving the Design of Existing Code. Addison-Wesley Professional, 1999. ISBN-13: 978-0201485677. Martin Fowler. Refactoring.com. Joey Paquet, 2006-2014