Chapter 5. Unnecessary Complexity

Note

“You aren't gonna need it.”–Ron Jeffries

Code is sometimes more complicated than it has to be to solve the problem at hand. There are two causes for this problem:

  • Sometimes code gets complicated for historical reasons (e.g., there can be code rot—the leftovers from old ways of doing things), but it no longer needs the complexity.

  • Another cause of complexity is the practice of overgeneralizing the design. This is often in anticipation of future requirements, or premature performance tuning.

Remove these problems when you run into them. You'll often find that this can lead to further insight and simplification.

Smells Covered

  • Dead Code

  • Speculative Generality

Dead Code

Symptoms

  • A variable, parameter, field, code fragment, ...

Get Refactoring Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.