001: Time to Understanding

September 09, 2010

WHAT

I spent an hour trying to figure out what a validation class did. By the end, I liked the concept and mentioned it in a daily wrap-up meeting. It was rightly rebuked as being full of code smells.

WHY

  1. Method 1 in the class created two array lists
  2. The method passed those empty lists to Method 2 with a full array of Strings
  3. Method 2 iterated through the array, each time passing both empty lists to Method 3
  4. Method 3 did a validity check and mutated one of the lists
  5. The whole of the class was dependent on difficult-to-test side effects

LESSON

Good code doesn’t take an hour to understand. If intention is not immediately obvious, it’s not good code.


Profile picture

Written by @sghill, who works on build, automated change, and continuous integration systems.