Post on 15-Jan-2015
description
transcript
Refactoring
Aman & Chirag
ThoughtWorks Pune
If it ain’t broken, why fix it?
Good programmers write code that humans can understand
You write code once;it gets read many times
To regain control on a program that is getting out of hands
To make the next change easier
This brings us to Refactoring
Refactoring in Action
Code Smells
Duplicated Code
Long Method
Comments
Divergent Change
Shotgun Surgery
Feature Envy
Lazy Class
Switch Statements
Primitive Obsession
Method Chains
Refactoring Catalog
Refactoring Catalog
Composing methods
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Refactoring Catalog
Simplifying Conditional Expressions
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Refactoring Catalog
Making Method Calls Simpler
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Source: refactoring.com
Accompanying XP Practices
• TDD : “Red - Green - Refactor” mantra
• Continuous Integration
• Collective Code Ownership
• Pair Programming
Next steps for you
• Go read the book!!!
• Practice small refactorings– Explore the “Refactor” menu of your IDE
• Keep a look out for code smells in your project
To sum it up…
• Refactoring is a good technique to clean up code
• Refactoring leads to better design (especially with Test-Code-Refactor cycles)
• Most important of all: it leaves a nice feeling at the end of it all!
Thank You
• Aman King– king@thoughtworks.com
• Chirag Doshi– chirag@thoughtworks.com