TDD Antipattern

Before I piss off the part of the world that loves test driven development let me say I'm not dissing it right now! I might save that for another time. ;-)What I am saying is that you can implement it poorly. Of course you can do anything related to programming poorly, but now I'll concentrate on TDD.I've encountered bits of code recently that are so all over the place spaghetti that I have trouble making heads or tails of it. I realized that the problem that I saw was the result of an experimental foray into TDD. The issue was every bit of functionality brought with it several hangers-on:

  • The class the implements the functionality
  • The interface for the class the implements the functionality
  • The factory class for that class
  • The interface for the factory that creates the class
  • The code that sets up the default factory

Now, if the functionality that we were talking about happens to be a largish subsystem then the added mental load of parsing all of this isn't too high. But when the functionality is so simple it just delegates to something else.  ???  When the code base has dozens of these things scattered everywhere, it makes things hard to read. Tracing through five code snippets scattered in four or five classes does a number on your mental state. When you finally get the the thing that does the work and you're immediately sent down a different, equally contorted, path it just gets damn frustrating.I've said it many times that code is for humans. The compiler can read all sorts of crap code that I've never been able to read. The code is for me not the computer. That's the reason we have all sorts of conventions about spacing, formatting, naming and everything else. When a pattern gets in the way of the readability of the code itself, I call FAIL on that pattern.You might counter that the tests make sure the code work. I suppose that might be the case, but if I can't figure out what the code does then the correctness is the last of my concerns; I don't even know the intent of the code!A test for all of this unknown functionality is a strange thing indeed.I think the underlying flaw here is that someone was trying to implement a TDD project without using a mocking framework. I have mixed opinions of some of the various mocking frameworks out there, but almost anything would be better than the code I was working my way though.A point to remember: Don't let an experiment get in the way of the intrinsic beauty and cleanliness of the code that you're writing.

Previous
Previous

Monday food nights: a weird way to diet!

Next
Next

3D movies: Where's the beef?