refactoring (tdd mini serie) haarlem software developer meetup
TRANSCRIPT
Confidential Page 1
KvK 53479335
Lichtfabriekplein 1, 2031 TE Haarlem
P.O. Box 2031 , 2002 CA Haarlem
+31 (0)88 248 1632, [email protected]
www.ximedes.com
Meetup Sponsor:
Test Driven DevelopmentRefactor Safely
Haarlem Software Developer Meetup@mcbeelen
01-10-2015 Confidential Page 3
01-10-2015 Confidential Page 4
Refactoring is a controlled technique for improving the design of an existing code base
Its essence is applyinga series of
small behavior-preserving transformations
01-10-2015 Confidential Page 5
01-10-2015 Confidential Page 6
01-10-2015 Confidential Page 7http://pitest.org/
01-10-2015 Confidential Page 8
01-10-2015 Confidential Page 9
BloatersLong methods, Many primitive fields, Complex conditionals
Object-Orientation AbusersSwitch-statements, Temporary Fields
Change PreventersBad names, Magic Numbers, Solution Sprawl
CouplersTrain wrecks, Feature Envy
DispensablesComments, Duplicate Code, Dead code
01-10-2015 Confidential Page 10
Rename Field Rename MethodExtract MethodInline Method
Move Field Move Method
Introduce Parameter ObjectmakeAlive(x, y) makeAlive(coordinate)
Extract Class
Extract Interface
01-10-2015 Confidential Page 11
Replace Conditional with Polymorphism
if (cell.isAlive()) {// handleAlive
} else {// handleDead
}
AliveCell.evolve() DeadCell. evolve()
01-10-2015 Confidential Page 12
Decompose Conditional
if (income > 25000 && dept < 1000) {maxLoan = income * largeFactor;newLoad = maxLoad – debt;return newLoad * normalPercentage
} else {maxLoan = income * smallFactor;newLoad = maxLoad – debt;return newLoad * highPercentage
}
if (isCreditWorthy()) {calculateOptimistic()
} else {calculatePessimistic()
}
01-10-2015 Confidential Page 13
01-10-2015 Confidential Page 14
01-10-2015 Confidential Page 15
01-10-2015 Confidential Page 16
01-10-2015 Confidential Page 17
1. You are here to LEARN. (and have fun)
2. Try to do your best.
3. Work in pairs.Find a partner in a similar programming language and operating system
01-10-2015 Confidential Page 18
01-10-2015 Confidential Page 19
Preparation for the kata’s:Git clone:https://github.com/emilybache/
Tennis-Refactoring-Kata
01-10-2015 Confidential Page 20
https://martinfowler.com/articles/workflowsOfRefactoring/
https://refactoring.guru/
https://sourcemaking.com/refactoring
References
Thanks for your attendance!
Global Day of Code Retreat: 18 November
Haarlem Software Developer Meetup