by Leon Rosenshein

Error Based Development

Wow, a different error message... Finally, some progress

I’ve often (usually? almost always?) found it easier to write code than it is to debug it. Even code I recently wrote. If nothing else, when I’m writing code I have all the context in my head and I know how all of the API calls are going to respond. Even if I’m wrong, I know what I’m expecting and I write the code accordingly. Of course, that’s not always the case, which leads to debugging.

Some days the debugging is easy. I can look at the incorrect result, error message, or stack trace and know what I need to do to fix the problem. Other times there’s enough info to point me at a section of the code and I can trace it through and find the issue. I can try different inputs and write special debugging code to help me understand what’s going on.

Other days though it’s a struggle. The error messages don’t help. Code inspection gets you nowhere. Debug code doesn’t even help. No matter what you do the error keeps happening and you get no extra information. This happens most often with 3rd party libraries and web calls because all you’ve got is the documentation. So you try changing something as a way to map the boundaries of the problem.

And nothing changes. Google searches. Stack overflow. The expert on the team. Nothing helps. So you go back to first principles and build a walking skeleton that has just enough meat on the bones to work. Then you keep adding to it until it breaks the way the thing your debugging breaks. Or conversely, you start taking things out of the broken thing until something changes.

Then you can really start debugging. You’re back in control of the system. Or at least having some kind of influence over it. Because without being able to influence the system you can’t characterize the problem or drive to a solution.

There have been countless times this has happened to me. I’ve worked for hours trying to vary the inputs subtly so that I can understand how the system is actually responding. Trying to get to the point where the error is in code I have influence over. So that I can fix it.

But as annoying as that is, it reminds me how much better things are now. Where I can click a button or run a single command and the system makes sure that I’m exercising the code that I’m working on. Not like things used to be. Before Makefiles having nothing happen was common. To actually see your change was a multi-step process. Change the code in some editor. Save the code. Compile the code. Link the code (at however many levels are needed). Run the new executable. Miss any one of those steps and nothing changes.

Sometimes I miss those days :)