Why Should We Refactor?

Refactoring is not a "silver bullet", but a valuable tool.

đź—Ľ Refactoring Improves the Design of Software

  • Without refactoring, the internal design of software tends to decay.

  • Code changes to achieve short term goals, without a full comprehension of the architecture, result in a loss of structure.

  • An important aspect of improving design is to eliminate duplicated code.

    • Poorly designed code takes more code to the same thing, often due to duplication.

    • The more code there is, the harder it is to modify correctly.

đź§  Refactoring Makes Software Easier to Understand

  • We need to think about the next programmer (often ourselves) reading our code.

    • How can we setup the next change so it takes hour(s) instead of days?

  • Refactoring helps make the code more readable.

  • A little time spent on refactoring can make the code better communicate its purpose.

🪲 Refactoring Helps Find Bugs

  • If we refactor code, we work deeply on understanding what it does.

  • Then we put that understanding back in the code.

  • By clarifying the structure of a program, we clarify certain assumptions made such that we often can't avoid spotting bugs.

  • Refactoring makes us more effective at writing robust code.

⚡Refactoring Helps Program Faster

  • Refactoring helps us develop code more quickly. This can be counterintuitive.

  • Internal quality of software is the difference between features that can be delivered quickly vs those that take a long time.

  • Modularity allows us to understand a small subset of the code base to make a change.

  • Clear code makes it less likely to introduce a bug.

  • Design Stamina Hypothesis: By putting effort into good internal design, we increase stamina of the software effort, allowing us to go faster for longer.

  • Good design is difficult to do up front. Refactoring is vital to improving design over time, even as the needs of the program change.

Last updated