9 Love deleting code


This chapter covers:

  • Understanding how code slows down 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 due to the functionality they provide. The functionality comes from code, therefore it is easy to think that code is implicitly valuable. This is not the case code is a liability. It is a necessary evil we have to live with to get functionality.

Another reason that we tend to feel code is valuable, is that it is expensive to produce. It requires skilled workers to spend lots of time, and 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 no matter if it is valuable or not.

Every programmer has tried getting bored with a manual task and thinking “I can automate this.” In many cases, this is indeed why we became programmers. However, we have also tried getting distracted with the automation code so much that it steals focus from the original problem, and ended up spending more time automating it than it would have taken to solve the problem manually.

9.1. Deleting code may be the next frontier

9.2. Delete code to get rid of technical-ignorance, -waste, -debt and -drag

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. Categories for code based on intimacy

9.4. Deleting code in a legacy system

9.4.1. Using strangler fig pattern to get insight

9.4.2. Using strangler fig pattern to improve the code

9.5. Deleting code from a frozen project

9.5.1. Make the desired outcome the default

9.5.2. Minimize waste with spike and stabilize

9.6. Deleting branches in version control

9.6.1. Minimize waste by enforcing a branch limit

9.7. Deleting code documentation

9.7.1. Algorithm to determine how to codify knowledge

9.8. Deleting testing code

9.8.1. Delete optimistic tests

9.8.2. Delete pessimistic tests

9.8.3. Fix or delete flaky tests

9.8.4. Refactor the code to get rid of complicated tests

9.8.5. Specialize tests to speed them up