際際滷

際際滷Share a Scribd company logo
Metric Driven Refactoring
Metrics
 The Bad
 The Good
 The Compromise
The Bad
 Often misleading
 Often misunderstood

 Lines of Code
 Number of Defects
 Turn time
The Good
 Can add objectivity to a
  subjective exercise
 Can help us focus on
  problem areas
 Can provide guidance at
  an early stage
The Compromise
 Metrics must be easily
  understood
 Metrics must provide
  actionable data
 Metric must be easy to
  calculate
What is Refactoring
 Small incremental
  changes
 Changes the internal
  structure
 Does not change the
  external behavior
Why Refactor
   Improve maintainability
   Improve performance
   Improve legibility
   Make code reusable
   Pay off design deficit
Code Smells
 Indicate that something
  maybe wrong with code
 Smells point to the
  need to refactor
 Individual smells are
  often associated with
  specific refactors
Sample Code Smells
   Long method
   Feature Envy
   Switch Statement Smell
   Shot Gun Surgery
   Large Class
   Comments
Smelly Metrics
 Metrics that Help
  identify Code in need of
  Refactoring
 Metric provides discrete
  values that can be
  compared against
  guidelines
Instruction Count
 Number of IL
  Instructions in a
  Method
 More instructions =
  Longer Method
 More Instructions =
  Less Focused Method
 More Instructions =
  More Effort to Support
Cyclomatic Complexity
 Number of Logical Paths
  Through a Method
 Number of Test Cases
  Needed for Full
  Coverage
 Higher Complexity =
  More Difficult to
  Support
 Higher Complexity =
  More likely to Have
  Errors
Guidelines
 Guidelines  Not Hard
  and Fast Rules
 Exceptions Allowed but
  Must be Understood
 200 Instructions per
  Method or Less
 Cyclomatic Complexity
  below 10
 Cyclomatic Complexity
  = 1 in a View
Running Metrics
Common Refactors
 Extract Method
 Replace Method with
  Method Object
 Decompose Conditional
Apply Some Refactors
New Best Practices
 Review Metrics Before
  and After Each Round of
  Code Changes
 Do No Harm
 Improve the Methods
  that You Touch
 Adhering to these
  Guidelines will Create
  Better Software
Where to Get More Information
 http://www.geekswithb
  logs.net/nharrison
 http://www.simple-
  talk.com/author/nick-
  harrison/
 http://www.refactoring.
  com/catalog/index.html
 http://www.red-
  gate.com/products/refl
  ector/index.htm
Ad

Recommended

Introduction to agile
Introduction to agile
onewomanmore witl
Mihai mahulea the zen of test driven development
Mihai mahulea the zen of test driven development
Codecamp Romania
Continuous testing for continuous delivery
Continuous testing for continuous delivery
David Hart
Best Practices In Apparel Color Communication
Best Practices In Apparel Color Communication
Michelle Roberts
Code Inventory
Code Inventory
Nick Harrison
[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Lets all get along. Clean Code please! - By: Christophe K. Ngo,...
DevDay Da Nang
Clean Code
Clean Code
swaraj Patil
Refactoring PHP
Refactoring PHP
Adam Culp
Code Refactoring
Code Refactoring
Milan Vukoje
Keeping code clean
Keeping code clean
Brett Child
Refactoring
Refactoring
AngelLuisBlasco
Refactoring 2 The Max
Refactoring 2 The Max
Alfredo Morresi
Chapter17 of clean code
Chapter17 of clean code
Kuyseng Chhoeun
Agile Metrics
Agile Metrics
Erik Weber
Quality metrics and angular js applications
Quality metrics and angular js applications
nadeembtech
Measuring Your Code
Measuring Your Code
Nate Abele
Refactoring workshop
Refactoring workshop
Itzik Saban
EFFECTIVE IMPLEMENTATION OF AGILE PRACTICES OBJECT ORIENTED METRICS TOOL TO...
EFFECTIVE IMPLEMENTATION OF AGILE PRACTICES OBJECT ORIENTED METRICS TOOL TO...
ijseajournal
Clean Code
Clean Code
Chris Farrell
Improving your CFML code quality
Improving your CFML code quality
Kai Koenig
Integreation
Integreation
Sean Killeen
Transitioning to quality software
Transitioning to quality software
M叩rton M辿sz叩ros
Mine Your Own Code
Mine Your Own Code
Peter Norrhall
Refactoring Fest
Refactoring Fest
Naresh Jain
Day2 - Refactoring (Lecture SS 2015)
Day2 - Refactoring (Lecture SS 2015)
wolframkriesing
Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
Igor Moochnick
Best-Practices-in-Writing-Clean-Maintainable-Code
Best-Practices-in-Writing-Clean-Maintainable-Code
Ozias Rondon
Big code refactoring with agility
Big code refactoring with agility
Luca Merolla
Revisiting refactoring
Revisiting refactoring
Nick Harrison
Refactoring workshop
Refactoring workshop
Nick Harrison

More Related Content

Similar to Metric driven refactoring (20)

Code Refactoring
Code Refactoring
Milan Vukoje
Keeping code clean
Keeping code clean
Brett Child
Refactoring
Refactoring
AngelLuisBlasco
Refactoring 2 The Max
Refactoring 2 The Max
Alfredo Morresi
Chapter17 of clean code
Chapter17 of clean code
Kuyseng Chhoeun
Agile Metrics
Agile Metrics
Erik Weber
Quality metrics and angular js applications
Quality metrics and angular js applications
nadeembtech
Measuring Your Code
Measuring Your Code
Nate Abele
Refactoring workshop
Refactoring workshop
Itzik Saban
EFFECTIVE IMPLEMENTATION OF AGILE PRACTICES OBJECT ORIENTED METRICS TOOL TO...
EFFECTIVE IMPLEMENTATION OF AGILE PRACTICES OBJECT ORIENTED METRICS TOOL TO...
ijseajournal
Clean Code
Clean Code
Chris Farrell
Improving your CFML code quality
Improving your CFML code quality
Kai Koenig
Integreation
Integreation
Sean Killeen
Transitioning to quality software
Transitioning to quality software
M叩rton M辿sz叩ros
Mine Your Own Code
Mine Your Own Code
Peter Norrhall
Refactoring Fest
Refactoring Fest
Naresh Jain
Day2 - Refactoring (Lecture SS 2015)
Day2 - Refactoring (Lecture SS 2015)
wolframkriesing
Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
Igor Moochnick
Best-Practices-in-Writing-Clean-Maintainable-Code
Best-Practices-in-Writing-Clean-Maintainable-Code
Ozias Rondon
Big code refactoring with agility
Big code refactoring with agility
Luca Merolla
Code Refactoring
Code Refactoring
Milan Vukoje
Keeping code clean
Keeping code clean
Brett Child
Refactoring 2 The Max
Refactoring 2 The Max
Alfredo Morresi
Chapter17 of clean code
Chapter17 of clean code
Kuyseng Chhoeun
Agile Metrics
Agile Metrics
Erik Weber
Quality metrics and angular js applications
Quality metrics and angular js applications
nadeembtech
Measuring Your Code
Measuring Your Code
Nate Abele
Refactoring workshop
Refactoring workshop
Itzik Saban
EFFECTIVE IMPLEMENTATION OF AGILE PRACTICES OBJECT ORIENTED METRICS TOOL TO...
EFFECTIVE IMPLEMENTATION OF AGILE PRACTICES OBJECT ORIENTED METRICS TOOL TO...
ijseajournal
Improving your CFML code quality
Improving your CFML code quality
Kai Koenig
Transitioning to quality software
Transitioning to quality software
M叩rton M辿sz叩ros
Refactoring Fest
Refactoring Fest
Naresh Jain
Day2 - Refactoring (Lecture SS 2015)
Day2 - Refactoring (Lecture SS 2015)
wolframkriesing
Arch factory - Agile Design: Best Practices
Arch factory - Agile Design: Best Practices
Igor Moochnick
Best-Practices-in-Writing-Clean-Maintainable-Code
Best-Practices-in-Writing-Clean-Maintainable-Code
Ozias Rondon
Big code refactoring with agility
Big code refactoring with agility
Luca Merolla

More from Nick Harrison (9)

Revisiting refactoring
Revisiting refactoring
Nick Harrison
Refactoring workshop
Refactoring workshop
Nick Harrison
Introducing fx cop
Introducing fx cop
Nick Harrison
Developer power tools
Developer power tools
Nick Harrison
Revisiting Refactoring
Revisiting Refactoring
Nick Harrison
Reflecting On The Code Dom
Reflecting On The Code Dom
Nick Harrison
Refactoring Workshop
Refactoring Workshop
Nick Harrison
The Nature Of Patterns
The Nature Of Patterns
Nick Harrison
Adaptive Architecture
Adaptive Architecture
Nick Harrison
Revisiting refactoring
Revisiting refactoring
Nick Harrison
Refactoring workshop
Refactoring workshop
Nick Harrison
Introducing fx cop
Introducing fx cop
Nick Harrison
Developer power tools
Developer power tools
Nick Harrison
Revisiting Refactoring
Revisiting Refactoring
Nick Harrison
Reflecting On The Code Dom
Reflecting On The Code Dom
Nick Harrison
Refactoring Workshop
Refactoring Workshop
Nick Harrison
The Nature Of Patterns
The Nature Of Patterns
Nick Harrison
Adaptive Architecture
Adaptive Architecture
Nick Harrison
Ad

Metric driven refactoring

  • 2. Metrics The Bad The Good The Compromise
  • 3. The Bad Often misleading Often misunderstood Lines of Code Number of Defects Turn time
  • 4. The Good Can add objectivity to a subjective exercise Can help us focus on problem areas Can provide guidance at an early stage
  • 5. The Compromise Metrics must be easily understood Metrics must provide actionable data Metric must be easy to calculate
  • 6. What is Refactoring Small incremental changes Changes the internal structure Does not change the external behavior
  • 7. Why Refactor Improve maintainability Improve performance Improve legibility Make code reusable Pay off design deficit
  • 8. Code Smells Indicate that something maybe wrong with code Smells point to the need to refactor Individual smells are often associated with specific refactors
  • 9. Sample Code Smells Long method Feature Envy Switch Statement Smell Shot Gun Surgery Large Class Comments
  • 10. Smelly Metrics Metrics that Help identify Code in need of Refactoring Metric provides discrete values that can be compared against guidelines
  • 11. Instruction Count Number of IL Instructions in a Method More instructions = Longer Method More Instructions = Less Focused Method More Instructions = More Effort to Support
  • 12. Cyclomatic Complexity Number of Logical Paths Through a Method Number of Test Cases Needed for Full Coverage Higher Complexity = More Difficult to Support Higher Complexity = More likely to Have Errors
  • 13. Guidelines Guidelines Not Hard and Fast Rules Exceptions Allowed but Must be Understood 200 Instructions per Method or Less Cyclomatic Complexity below 10 Cyclomatic Complexity = 1 in a View
  • 15. Common Refactors Extract Method Replace Method with Method Object Decompose Conditional
  • 17. New Best Practices Review Metrics Before and After Each Round of Code Changes Do No Harm Improve the Methods that You Touch Adhering to these Guidelines will Create Better Software
  • 18. Where to Get More Information http://www.geekswithb logs.net/nharrison http://www.simple- talk.com/author/nick- harrison/ http://www.refactoring. com/catalog/index.html http://www.red- gate.com/products/refl ector/index.htm