Code Smells

How do you know when you should begin refactoring?

Code Smell


A "sniffable" characteristic in source code that possibly indicates a deeper problem.

Code smells are not bugs, only indicators that some piece of code may deserve a closer look. Code smells follow a few categories1:

  • Bloaters
    • classes or methods that are too big or complex
      • large class
      • long method
      • long parameter list
  • Non-object-orientation
    • incomplete or incorrect application of OO principles
      • switch statements
      • methods are all static
  • Change preventers
    • a change made in one place entails many changes in other places
      • shotgun surgery
        • a single change must be made to multiple classes simultaneously
      • divergent change
        • many changes are needed to a single class
  • Dispensables
    • unneeded or pointless code
      • dead code
      • duplicate code
      • data class
  • Couplers
    • excessive coupling between modules
      • inappropriate intimacy
      • middleman
        • class that only performs one action and delegates work to other classes
      • message chains
        • v.a().b().c().d()

Footnotes