Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Refactoring

Michel
February 13, 2019

Introduction to Refactoring

Michel

February 13, 2019
Tweet

Other Decks in Programming

Transcript

  1. What makes this a great book? • Refactoring Vocabulary •

    Refactors • Code Smells • Approach (refactor, test, commit) • For each type of refactor • Why • Example • Steps to refactor
  2. What is refactoring? • Refactoring is the process of changing

    a software system in a way that does not alter the external behavior of the code yet improves its internal structure • Changes in small steps • Change code • Run tests • Commit
  3. First Example • First step in refactoring: solid set of

    tests • Test Feedback • Separate different parts • Switch to Visual Studio and refactor this code base: • https://github.com/michelschep/refactoring-first-example
  4. Why refactor? • Improves the design of software • Makes

    software easier to understand • Helps find bugs • Helps program faster
  5. When refactor? • Preparatory refactoring: make it easier to add

    a feature • Comprehension refactoring: make it easier to understand • Litter-pickup refactoring (boy scout rule) • Refactoring in a code review (pair programming)
  6. What do I tell my manager? • Don’t tell! •

    Software developers are professionals • Our job is to build effective software as rapidly as we can • Refactoring is a big aid into building software quickly • I’m being paid for my expertise in programming new capabilities fast, and the fastest way is by refactoring – therefore I refactor
  7. When it is not refactoring… “If someone says their code

    was broken for several days while they are refactoring, you can be pretty sure the were not refactoring” – Martin Fowler
  8. Refactoring Vocabulary • Extract Function • Inline Variable • Change

    Function Declaration • Split Loop • Slide Statements • Replace Temp with Query
  9. Oh and what about performance? • It is much easier

    to improve the performance of a well-refactored code base • Example: Replace Temp with Query (178)