Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Smells & Refactoring

โญโญ intermediateโณ 14 min read๐Ÿ“ Lesson 115 of 180

Long methods, primitive obsession, feature envy โ€” and comments that explain why instead of what.

Code smells and the refactoring reflex

Smells don't prove a bug โ€” they invite a look:

  • Long method โ€” many blank lines and levels; extract methods
  • Primitive obsession โ€” money as int, phone as String everywhere; introduce tiny value types
  • Data clumps โ€” city, street, zip traveling together forever; make an Address record
  • Feature envy โ€” a method reaching into another object's getters more than its own fields; move it there
  • Shotgun surgery โ€” one change touches ten files; the concept needs a home
  • Comment explaining WHAT โ€” the code should say what; comments say why (constraints, links, tradeoffs)
// before โ€” primitive obsession + long method
static boolean ok(String u, String p) { ... }

// after โ€” names and types carry the design
static boolean isPasswordValid(Password candidate, PasswordPolicy policy) { ... }

Refactoring discipline (from Module 12): small verified steps, tests green between each, behavior unchanged by construction.