your code is collapsing- how refactoring can save your ass 2012 03-01 - confoo
DESCRIPTION
One of the most overlooked Agile techniques may also be the most useful one. In the context of software product development, Refactoring (improving the design of existing code) is absolutely mandatory to continuously deliver quality code in reasonable timeframes. Teams that do not practice continuous refactoring see their quality and velocity go down with time. Developers should understand from this presentation: - How to explain the topic to managers? - How to make sure refactoring is done, and regularly? Managers should take away from this session: - What is refactoring? - What to do to maintain a good velocity as products are being built?TRANSCRIPT
Your Code is CollapsingHow Refactoring Can Save Your
Thursday, 1 March, 12
DISCLAIMER
Refactoring can generate endless discussions. What we will share
today are original thoughts on the topic, in order to provide ideas to address your own situation (every
situation is different)
Thursday, 1 March, 12
Lack of Refactoring
Thursday, 1 March, 12
GrandPerspectiveThursday, 1 March, 12
DbVisualizerThursday, 1 March, 12
StatSVN
Developers modify code much more often than they write new code
Thursday, 1 March, 12
Our brain’s processing power is extremely overrated
Thursday, 1 March, 12
Thursday, 1 March, 12
Thursday, 1 March, 12
Lack of Refactoring causes:
Slower DeliveryMore DefectsLower Morale
It’s a vicious circle!
Thursday, 1 March, 12
“If it ain’t broke, don’t fix it”
Thursday, 1 March, 12
When reusing the source code ends up costing more than
starting from scratchThursday, 1 March, 12
You say: “technical debt”
I ask: “credit history?”
Thursday, 1 March, 12
Solution
The solution involves change management techniques. It requires education, awareness, incentives, making metrics visible, reports and alerts automatically generated (CI). Different levels of awareness will cause frustrations.You will often need external help (coaching.).
Thursday, 1 March, 12
Solution
1. NEW CODE BASE: continuous refactoring (and automated tests). Ideally, TDD (Red, Green, Refactor)
2. EXISTING CODE BASE: cost-benefit analysis (how long is the product to be supported?)
Thursday, 1 March, 12
Raising Awareness
Thursday, 1 March, 12
Explain refactoring to non-programmers with
writing recipes
Thursday, 1 March, 12
Thursday, 1 March, 12
Thursday, 1 March, 12
How much time does it take to spot the error?
Thursday, 1 March, 12
Preheat oven to 425F and place rack in center.Wash the cherries, remove stems and pits.In blender, process flour, salt, eggs, sugar,and vanilla extract until completely smooth.Let batter rest.In large 9-inch nonstick skillet melt butter over medium heat.Add cherries, and cook for 3 minutes. Add the remaining sugar and cook for 2 more minutes.Pour the batter over the cherries and bake for about 20 minutes or until the clafoutis is puffed, set, and golden brown around the edges.
1/2 cup all purpose flour1/4 teaspoon
salt2 large eggs2 tbsp sugar3/4 cup milk1/2 teaspoon
vanilla extract
1 lb fresh cherries
1 tbsp butter2 tbsp sugar
Thursday, 1 March, 12
Solution
Thursday, 1 March, 12
Preheat oven to 425F and place rack in center.Wash the cherries, remove stems and pits.In blender, process flour, salt, eggs, sugar, milk,and vanilla extract until completely smooth.Let batter rest.In large 9-inch nonstick skillet melt butter over medium heat.Add cherries, and cook for 3 minutes. Add the remaining sugar and cook for 2 more minutes.Pour the batter over the cherries and bake for about 20 minutes or until the clafoutis is puffed, set, and golden brown around the edges.
1/2 cup all purpose flour1/4 teaspoon
salt2 large eggs2 tbsp sugar3/4 cup milk1/2 teaspoon
vanilla extract
1 lb fresh cherries
1 tbsp butter2 tbsp sugar
Thursday, 1 March, 12
Let’s Refactor
Thursday, 1 March, 12
Preheat oven to 425F and place rack in center.Wash the cherries, remove stems and pits.
In blender, process flour, salt, eggs, sugar, milk,and vanilla extract until completely smooth.
Let batter rest.
In large 9-inch nonstick skillet melt butter over medium heat.
Add cherries, and cook for 3 minutes. Add the remaining sugar and cook for 2 more minutes.Pour the batter over the cherries and bake for about 20 minutes or until the clafoutis is puffed, set, and golden brown around the edges.
1 lb fresh cherries
1/2 cup flour1/4 teaspoon salt
2 large eggs2 tbsp sugar3/4 cup milk1/2 teaspoonvanilla extract
1 tbsp butter
2 tbsp sugar
Thursday, 1 March, 12
And now?
Thursday, 1 March, 12
Preheat oven to 425F and place rack in center.Wash the cherries, remove stems and pits.
In blender, process flour, salt, eggs, sugar,and vanilla extract until completely smooth.
Let batter rest.
In large 9-inch nonstick skillet melt butter over medium heat.
Add cherries, and cook for 3 minutes. Add the remaining sugar and cook for 2 more minutes.Pour the batter over the cherries and bake for about 20 minutes or until the clafoutis is puffed, set, and golden brown around the edges.
1 lb fresh cherries
1/2 cup flour1/4 teaspoon salt
2 large eggs2 tbsp sugar3/4 cup milk1/2 teaspoonvanilla extract
1 tbsp butter
2 tbsp sugar
Thursday, 1 March, 12
Source code is invisible (by default)
Problems with source code are even less visible
Thursday, 1 March, 12
Junior developers don’t see the point. Senior developers
don’t care.. Project Managers, well...
Thursday, 1 March, 12
MAKE IT VISIBLE!
Even Better:
MAKE IT STINK!
Thursday, 1 March, 12
Code Smellshttp://www.codinghorror.com/blog/2006/05/code-smells.html
Thursday, 1 March, 12
Ideas
1. Sonar (SonarSource.org) can display, for each build: code coverage, complexity metrics, rules compliance...2. Use in conjunction with Continuous Integration (Jenkins). Configure to alert when non compliant3. Name Code Quality Managers4. Regular Retrospectives to discuss rules
Thursday, 1 March, 12
SonarThursday, 1 March, 12
Ideas5. Provide realistic estimates which include time to refactor (include in your definition of DONE)6. Multiple little refactorings are better than large ones7. Rule of thumb: dedicate 10% of your time to refactor (before each commit)8. Metrics: watch TRENDs, NOT absolute numbers
Thursday, 1 March, 12
Books
• Refactoring by Martin Fowler (1999)
• Refactoring to Patterns by Joshua Kerievsky (2004)
• Code Complete 2 by Steve McConnell (2004)
• Clean Code by Robert C. Martin (2008)
Thursday, 1 March, 12
@ogourment
Thursday, 1 March, 12