Refactoring
Notes from Industrial Logic course
Extract example
def printOwing(amount):
printBanner()
print "name: %s" % name
print "amount: %f" % amount
def printLateNotice(amount):
printBanner()
print "name: %s" % name
print "amount: %f" % amountdef printOwing(amount):
printBanner()
printDetails()
def printLateNotice(amount):
printBanner()
printDetails()
def printDetails(amount):
print "name: %s" % name
print "amount: %f" % amountUnlocking the Awesome Power of Refactoring
by J. B. Rainsberger tech excellence talk
Deliberate practice, Learned Helplessness.
Nanosteps –> Microsteps –> Moves Repetition –> Ease –> Chunking (autonomic, subconscious, higher order thinking) –> Confidence –> Courage
Pattern: Item –> Collection (ex function arg)
- add extra arg
f(x) --> f(x, xs: List). - modifiy calls of
f(x)in the code base to use new signature. - modify
f(x)to usexsinstead ofx. - verify that the behaviour of
f()is the same. - remove
xso that we are left withf(xs).
Start practicing now: 30min refactoring at the end of a day or even week. Throw the changes away.
Practice is not performance!
“Cleaning the kitchen as you cook”.