9 Love deleting code

 

This chapter covers

  • Understanding how code slows development
  • Setting limits to prevent accidental waste
  • Handling transitions with the strangler fig pattern
  • Minimizing waste with the spike and stabilize pattern
  • Deleting anything that does not pull its weight

Our systems are useful because of the functionality they provide. The functionality comes from code, so it is easy to think that code is implicitly valuable—but this is not the case. Code is a liability. It is a necessary evil that we have to live with to get the functionality we need.

Another reason we tend to feel that code is valuable is that it is expensive to produce. Writing code requires skilled workers to spend lots of time (and consume lots of caffeine). Attributing value to something because we have spent time or effort on it is called the sunk-cost fallacy. Value never comes from investment alone but from the outcome of the investment. This is crucial to understand when working with code since we have to continually put effort into maintaining the code regardless of whether it is valuable.

Every programmer has become bored with a manual task and thought, “I can automate this.” In many cases, this is why we became programmers. However, it is easy to get so distracted by the automation code that it steals focus from the original problem, and we end up spending more time automating the problem than it would have taken to solve it manually.

9.1 Deleting code may be the next frontier

9.2 Deleting code to get rid of incidental complexity

9.2.1 Technical ignorance from inexperience

9.2.2 Technical waste from time pressure

9.2.3 Technical debt from circumstances

9.2.4 Technical drag from growing

9.3 Categorizing code based on intimacy

9.4 Deleting code in a legacy system

9.4.1 Using the strangler fig pattern to get insight

9.4.2 Using the strangler fig pattern to improve the code

9.5 Deleting code from a frozen project

9.5.1 Making the desired outcome the default

9.5.2 Minimizing waste with spike and stabilize

9.6 Deleting branches in version control

9.6.1 Minimizing waste by enforcing a branch limit

9.7 Deleting code documentation

9.7.1 Algorithm to determine how to codify knowledge

sitemap