And then the request came to add several new features that would exercise the currently-inflexible code. Panic! At this point I'm not even sure what exactly is wrong with this code, only that I have been struggling uphill somewhat every time I set out to use it. It's a little research project each time.
So I pour out my heart to my boss and the team member who's in the Customer role (it's an internal project, he really is the customer). "Oh boss, danger! There's something slowing me down, I know not exactly what, but I shall surely need extra time, etc.!" Too bad I let my fear run wild there. If I'd have had more patience and courage, everything would have been fine.
I wound up simply keeping one eye on the "problem" area of the code while I continued to make forward progress on the new features. Turned out there were two problems I was smelling, 1) a
longish.message.chain in violation of the Law of Demeter that was causing coupling problems, but only at 2-3 sites, and 2) inadequate model/presentation separation, a deeper and more widespread problem, but not hard to tackle either.
And now that I understand what problems I'm facing, I'm calm and confident about the code again and can implement the refactorings gradually with minimal disruption.
What did I learn?
- Code smells are good, not to be feared. They mean I'm learning about my code, and am about to make a nice improvement in its design once I figure out the source of the smell.
- It's good to be bothered about the state of the code, but don't worry about the annoyance until I understand it as a clearly defined problem. Then I can take concrete action.