Debugging - A True Story

Debugging – a True Story

By Steve

One time, when I was staying with my wife in an old apartment in beautiful Bulgaria (from whence she hails), I was taking a shower.
About halfway through it, I noticed out of the corner of my eye some kind of movement on the far wall, near the sink. But when I turned to look, there was nothing there. A minute later, I saw (or rather, didn't see) it again. This time, I stopped and watched.

And after another minute or so, Fred appeared.

The Uninvited Guest

Fred was a very big cockroach. (This story is actually true, so obviously for legal reasons I have not used his real name). I don't like to make fun of people, and I am sure that his Mum loved him very much, but he was a seriously ugly bug.

I'm a grown man and as such I'm not really afraid of anything (although if Fred, being the size that he was, had been a spider, I would probably be writing this on the soft walls of an asylum cell) but I am ashamed to say I may have screamed (in a very manly way of course) and thrown the shampoo at him.
Of course I missed. Fred and his Fred-like brethren are fast. Needless to say, it was a pretty quick shower.

I didn't tell anyone about Fred, because I didn't want to have to move into a hotel while the place was fumigated. And, it seemed that it really was Fred singular and not Fred plural (what do they call a herd of roaches anyway – a Nightmare, maybe?) and he seemed content to stay in the bathroom, I figured, what harm could it do to let him be?

Well, I'm not going to go into too much detail about what happened next, except to say that over the course of three days, Fred and I actually became quite used to one another (the Bulgarian summer is hot and sticky such that three showers a day is pretty normal) and dare I say, we became quite good friends.

It was the feel-good comedy of the summer: "A shy nerd takes a horrifically-ugly-unkillable-spawn-of-the-devil-bug on a road trip that will change their lives forever".
And during our wacky misadventures, I discovered that cockroaches have feelings too, and he discovered that a guy who recites the SOLID principles of OOP while he brushes his teeth is actually pretty cool - for a nerd.

Say hello to my little friend

Well, after three days things took unfortunately took a turn for the worse; the inevitable occurred and my wife met Fred. And as one tends to do when one finds one's supposed best friend in the shower with one's spouse, I got a little angry with him.

Things were said, threats were made, and it was decided that Fred had to go.

But I couldn't bring myself to, you know, whack the little guy; I respected him and his ability to survive a nuclear winter far too much for that. But he had to go, so I decided to track him down, capture him, and release him.

This proved to be a lot harder than you might think.
Most Bulgarian homes (especially the older ones from semi-communist times) have wet bathrooms; that is to say there isn't a separate shower unit. When you want to have a shower, you walk in, move some stuff out of the way and turn on the shower which sprays directly into the room.
This means that the room itself can end up quite disorganised; laundry baskets and various basins here and there, various towels and bathrobes scattered on various surfaces, cleaning products stuck wherever they will fit.
So many perfect places for a cockroach, on the run and with nothing left to lose, to hide.

In Socialist Bulgaria, Cockroach Trap You

I love Bulgaria and I love her people; but I don't think they would have understood if I'd gone into a shop and looked for a cockroach TRAP. It's just not how it's done over there. They'd probably have just given me a bottle of Rakia and a Shotgun. (I'm not kidding when I say that Fred was BIG)

Anyway, I figured that I'd catch Fred the same way I catch the (thankfully small) spiders that spend their summer vacations in our house in Ireland; a simple pint glass and a piece of card. Place the glass over the intended target, slide the card under the glass, invert, open a window, remove the card, and flick the wrist. Simple, effective, and nobody is hurt (well, I suppose they shake their tiny little spider fists at me afterwards and threaten to put a really bad review on Yelp, but whatever.)

Hide and Seek

Unfortunately, Fred was not on board with this approach AT ALL. Oh he would seem to be; he'd scuttle out from behind the bleach and sit there for ages, waving his long cockroach antennae as if to say "OK dude, I'm ready to go, let's do this." And then as soon as the glass would start to come down - poof! Gone. So fast I wouldn't even see him.
And it was such a mess, with things everywhere, I started to get very frustrated. I just couldn't track down this bug! But then it occurred to me.

What I needed, was a system. I needed organisation. I couldn’t find the bug because everywhere I looked, there were irrelevant details like soap and washing powder and loo rolls in the way. I needed to be able to look at this problem without any distractions.

So I refactored the bathroom.

I moved everything extraneous out of that bathroom, using a process of elimination to discard first the most likely, and then the most unlikely, of hiding places for Fred.
Eventually the bathroom was completely empty except for a single basin, used to catch drips from a leaky pipe, stuck in a far corner of the room.

Fred was behind that basin.

I have to say, in all fairness to Fred, that despite his previously wanton evasion, once the game was up he came quietly; he didn't move as the glass slid over him, didn't budge as I slid the card underneath and didn’t try to escape as I brought him out to the balcony.

I would later find a single tiny wet patch on the card that I like to think was caused by Fred shedding a single tear for the ending of our wonderful time together. But it's also possible that he just peed on it so I guess I'll never know. And I'll concede that I may also have shed a single tear as I flicked my wrist on the balcony and watched him plummet three stories and then spread his diaphanous wings to buzz away in the balmy summer dusk.

And just like that, he was gone.

I don't know where he went, and I mostly hope I never see him again; but I do sometimes wonder how he is, and what new adventures he found; and if he ever starred in a not-quite-as-funny-as-the-original-but-OK-I-guess sequel.
And so I do sometimes miss him, just a little bit.

So there you have it, that's the story of how I debugged a bathroom in Bulgaria.


You may be wondering, if this was really just an excuse for a bad pun and not at all about software development.
Yes, and No.
Because I never told you what the last thing Fred said to me; was let me tell you now.
I can't translate directly (my Bulgarian is terrible) but here's the gist of it:

"Ensure that you organise your code into distinct fractally-shaped modules and sub-modules such that when the overall system exhibits failure, you can rapidly diagnose the root cause. Remember this, Steve: deductive reasoning allows you to reach a conclusion by applying general rules that hold within single closed domain of discourse at a time, thus narrowing the range of sub-systems under consideration until only one is left.

And that one is the faulty one.

In other words, start where you observe the error and then constantly reduce your problem space by moving higher or lower in the system until you find the real source. High unit test coverage paired with Integration tests really helps with this approach."

And I have to say, this is pretty good advice, even if it did come from a cockroach.

Stephen Byrne

Read more posts by this author.