What I Learned from "Working Effectively with Legacy Code"

Contents

The page image is mind map made by myself. (Apologize you need to enlarge the picture if you want to take a look)

  • Hard find where to add new features
  • Mental overload when reading the code
  • Hard to identify the reported issue belongs to bug or feature
  • Hard to find the root cause when error happened
  • No tests existed
  • Sketch the concept first, don’t jump into the code directly
  • Figure out the responsibility of the system
  • Give the comment tag with corresponded responsibility to the lines of code
  • Even there is not testing, it is still recommended to create a new branch to do refactor
  • By extracting the method and moving variables, you can avoid to checking the code again
  • If the refactored code can work correctly then you can make sure you understand the code correctly
  • Hard to writing tests
  • We often think there only few of self business logics so no need to write the tests
  • If we writing the tests would cause the side effects
  1. Write a brief description for the code
  2. Separate the code responsibility
  3. Draw the design with class diagram
  • A higher level abstraction interface to the application
  • Let us can fake the method during test. (OOP support virtual method)
  • You want to completely separate out the dependency from API calls
  • Information for telling you the system currently break the change
  • Information for telling you why the system break the change
  • Instead, do extraction from high level piece and break dependency at the same time