Tuesday, April 18, 2017

Debugging is a Smell

I practice TDD.  And I realized that I'm irritated today with something I'm writing (in Node with promises), because I'm constantly using the debugger.

Using the debugger is a sign that something in your environment is causing your code to be difficult to reason about.  The error you get from your tests doesn't tell you what to do next, so you have to go on a fact finding mission.

Ideally, this fact finding mission would be a new test somewhere else.  But I can't write tests for code that isn't mine.  In this case, in the promises resolution parts of node, or the routing in the framework I'm using (Restify).  And to be fair, some of the stink here is my grasp of these frameworks.

One of the things I like best about TDD is how it surfaces classic old problems early: highly coupled code is hard to test. Lack of dependency injection is hard to test. Modules that do too many things are hard to test. And now, frameworks that have bad error handling and detection, they also are hard to test.