Return to site

CODE SMELL: Speculative generality ๐Ÿ”ฎ

December 10, 2022

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.