Home > Articles > Software Development & Management > Agile

  • Print
  • + Share This

Code Smells

Martin Fowler and Kent Beck use the metaphor of "code smells" to describe what you sense when you look at code. Code smells tend to be a "bad sign," rather than an indication that something is necessarily wrong. You may have heard a similar idea described as "anti-patterns" (after Brown et al. 1988) or "Spidey-sense" (after Stan Lee's Spider-man, 1996).

What potential danger signs might you see in code?

  • Classes that are too long

  • Methods that are too long

  • Switch statements (instead of polymorphism)

  • "Struct" classes (getters and setters but not much functionality)

  • Duplicate code

  • Almost (but not quite) duplicate code

  • Overdependence on primitive types (instead of introducing a more domain-specific type)

  • Useless (or wrong!) comments

  • Many more...

Some smells are obvious right away; you may not detect others until you're in the middle of refactoring.

Look at the original code above, and see what problems you can identify. (Don't restrict yourself to this list!)

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.