Return to site

CODE SMELL: Speculative generality 🔮

· coding,code-smell

This code smell happens when we add functionality that isn't really needed but we believe will be needed in the future 🔮. It often takes place in the form of unused data (parameters, fields in objects, columns in the database schema, among others), unused methods, and unnecessary classes.

Why is it bad? 👎

  • This leads to code that is more complex 🤯 than it has to be, and is harder to maintain over the long run.
  • Unnecessary functionality is a waste 🗑️ of time and resources.

How to fix it? 🔧

  • Remove unused parameters. 🧼
  • Remove unused method signatures when overloading. 🧹
  • Remove unnecessary classes and functions.🧽
  • Keep the structure of the code simple 😄: avoid over-engineering 🧠🧠 the solution and always keep the use case in mind.