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
![Page 1: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/1.jpg)
Your Code is CollapsingHow Refactoring Can Save Your
Thursday, 1 March, 12
![Page 2: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/2.jpg)
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
![Page 3: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/3.jpg)
Lack of Refactoring
Thursday, 1 March, 12
![Page 4: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/4.jpg)
GrandPerspectiveThursday, 1 March, 12
![Page 5: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/5.jpg)
DbVisualizerThursday, 1 March, 12
![Page 6: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/6.jpg)
StatSVN
Developers modify code much more often than they write new code
Thursday, 1 March, 12
![Page 7: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/7.jpg)
Our brain’s processing power is extremely overrated
Thursday, 1 March, 12
![Page 8: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/8.jpg)
Thursday, 1 March, 12
![Page 9: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/9.jpg)
Thursday, 1 March, 12
![Page 10: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/10.jpg)
Lack of Refactoring causes:
Slower DeliveryMore DefectsLower Morale
It’s a vicious circle!
Thursday, 1 March, 12
![Page 11: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/11.jpg)
“If it ain’t broke, don’t fix it”
Thursday, 1 March, 12
![Page 12: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/12.jpg)
When reusing the source code ends up costing more than
starting from scratchThursday, 1 March, 12
![Page 13: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/13.jpg)
You say: “technical debt”
I ask: “credit history?”
Thursday, 1 March, 12
![Page 14: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/14.jpg)
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
![Page 15: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/15.jpg)
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
![Page 16: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/16.jpg)
Raising Awareness
Thursday, 1 March, 12
![Page 17: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/17.jpg)
Explain refactoring to non-programmers with
writing recipes
Thursday, 1 March, 12
![Page 18: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/18.jpg)
Thursday, 1 March, 12
![Page 19: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/19.jpg)
Thursday, 1 March, 12
![Page 20: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/20.jpg)
How much time does it take to spot the error?
Thursday, 1 March, 12
![Page 21: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/21.jpg)
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
![Page 22: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/22.jpg)
Solution
Thursday, 1 March, 12
![Page 23: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/23.jpg)
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
![Page 24: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/24.jpg)
Let’s Refactor
Thursday, 1 March, 12
![Page 25: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/25.jpg)
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
![Page 26: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/26.jpg)
And now?
Thursday, 1 March, 12
![Page 27: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/27.jpg)
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
![Page 28: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/28.jpg)
Source code is invisible (by default)
Problems with source code are even less visible
Thursday, 1 March, 12
![Page 29: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/29.jpg)
Junior developers don’t see the point. Senior developers
don’t care.. Project Managers, well...
Thursday, 1 March, 12
![Page 30: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/30.jpg)
MAKE IT VISIBLE!
Even Better:
MAKE IT STINK!
Thursday, 1 March, 12
![Page 31: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/31.jpg)
Code Smellshttp://www.codinghorror.com/blog/2006/05/code-smells.html
Thursday, 1 March, 12
![Page 32: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/32.jpg)
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
![Page 33: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/33.jpg)
SonarThursday, 1 March, 12
![Page 34: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/34.jpg)
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
![Page 35: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/35.jpg)
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
![Page 36: Your Code is Collapsing- How Refactoring Can Save Your Ass 2012 03-01 - confoo](https://reader037.vdocuments.site/reader037/viewer/2022110306/5549fb62b4c905e56c8b4acf/html5/thumbnails/36.jpg)
@ogourment
Thursday, 1 March, 12