I walked into the kitchen, and put the kettle on, and put the fixings for coffee into my mug. The cat was bugging me for milk, so I gave him some.
He wouldn’t touch it, but just stared at me.
I petted his head and rubbed his back. Then he got into the milk. He needs the full dining experience.
I went to the back door, started rolling a cigarette and half-way through a nagging something in my head tried to get my attention.
“Oh, bugger,” I said out loud.
I’d found a bug in my mouse-interaction code. It was code that I hadn’t touched, or even looked at since maybe August last-year, when I wrote it initially. A nine-line function that turned mouse-clicks into proper UI-widget interactions.
Suddenly, the shape of that code was floating in my head, and it was the wrong shape. It didn’t … fit.
The code had never misbehaved, or done anything wrong, but that wasn’t the point. I knew it was wrong, and I had a feel for how it would misbehave. Even if I couldn’t remember the exact lines of code.
My instinct was telling me that mouse-clicks might pass through non-reactive UI elements and trigger reactive elements underneath. That had never happened, to my knowledge, but I was suddenly certain that it would.
So, I aborted making coffee, and my cigarette and went and looked at the code.
I was right. It was wrong. It would behave in exactly the wrong way that I had envisioned, if the circumstances ever came to pass (and they would!).
So, I fixed it. New code. New shape. It settles in more comfortably now.
This, though, is how I find bugs. 90% of the bugs I find aren’t because something goes wrong. In fact, the game behaves perfectly. It does everything it should, exactly as it should. I’ve seen no sign that there’s an issue, and nothing’s been reported.
But I’m in the bathroom, or having a cigarette, or trying to sleep, and there it is. I suddenly know that a bit of the code isn’t right, and in what way it isn’t right. There’s a kind of synaesthesia at work – the codebase exists in my head as a collection of shapes that aren’t shapes, and colours that aren’t colours.
Whatever I’m doing, or wherever I am, some part of my brain is walking over that model, looking for anomalies. And finding them wherever they are.
It would, perhaps, be nice if it could announce them right away, while I am actually writing the code, for example, but no. It chugs away in its own good time doing a whole-program analysis, and then bugging me about it when my attention is on other things.
At four-thirty in the morning, some noise sets the dog barking, which wakes me up in turn, and then that synaesthestic model is hanging in my head, focused on a rendering function, or caching algorithm, that’s working but is invisibly buggy. And I know what’s wrong. I can fix it in five minutes. If I got up.
Getting back to sleep again – or maintaining any kind of task-focus on anything else – is pretty hard when you’ve got one of these things dangling in your forebrain, insisting on being fixed.
Finding bugs the way regular people do (when things just plain break or misbehave) seems like a lot less trouble.