Advanced Programing practices

Slides:



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

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. What is refactoring ? In refactoring, you start with the basic code and make it better. Change the internal structure of the existing code.
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
Chapter 9 – Software Evolution and Maintenance
Maintenance Refactoring and Code Smells. Where are we? Over the semester we have talked about Software Engineering. The overall goal of software engineering.
Advanced Programing practices
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.
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.
Refactoring Improving the structure of existing code Refactoring1.
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
Composition of UML Described Refactoring Rules Presented by Chin-Yi Tsai.
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.
Advanced Programming in Java
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 1 Towards an Assessment of the Quality of Refactoring.
Informatics 122 Software Design II
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.
Writing Maintainable code Dr. Susan McKeever DT228/3 GUI Programming.
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.
Refactoring - 1 CS494: Intro. to Refactoring Readings: –Refactoring for everyone: How and why to use Eclipse's automated refactoring features. By David.
Modern Software Development Using C#.NET Chapter 6: Refactoring.
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.
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…
Catalog of Refactoring (6) Making Method Calls Simpler.
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:
Business Should Adopt Agile Testing. Test Driven Development is an essential software development way that is made by an automated test program which.
Refactoring and Code Smells
Advanced Programming Behnam Hatami Fall 2017.
بازآرایی برنامه Code Refactoring
Overview of Eclipse Lectures
Improving the structure of existing code
Refactoring and Code Smells
Advanced Programming Behnam Hatami Fall 2017.
Chapter 3 – Agile Software Development
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Refactoring and Code Smells
Refactoring and Code Smells
Refactoring and Code Smells
Presentation transcript:

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

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 externally observable 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-2018

Constantly during programming SOEN 6441 - Advanced Programming Practices Refactoring: when? Constantly during programming 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. Between each build in agile software development methods When using iterative or incremental 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. Joey Paquet, 2006-2018

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 requires proper testing, so it improves testability helps to find bugs Improve productivity improve code readability & comprehensibility simplify code structure Improve sustainability of development By improving the code’s structural quality, reducing confusion and making the code more understandable, it reduces the effort involved in further development. This is very important in agile software development methods, whose focus on productivity and changes are likely to create lower quality code. Without refactoring, agile methods are likely to create code whose further development will be exponentially costly. Joey Paquet, 2006-2018

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-2018

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-2018

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

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-2018

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-2018

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-2018

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-2018

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-2018

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-2018

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 incremental or 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. For build 2 and 3, you will have to report on the refactoring operations applied between builds. Joey Paquet, 2006-2018

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-2018