Daily #17 The "It doesn't work" Rant

A friendly rant. This is a lesson on debugging that I've taught to almost every single student of programming I've interacted with. Sooner or later it always comes up. Writing up the first draft of a possible post for CodeCurious here.


Don't ever say "It doesn't work". Instead tell me (or yourself, if you're rubber ducking):

What did I try, specifically what did I do?

What did I expect to happen?

Why did I expect that outcome?

If the outcome was not what I expected, did I get an error message?

What did it say? Yes the error message, what did it say? Read it again.

Sometimes there is an actual bug with our logic, sometimes it's a typo. Sometimes our expectations are wrong.

When we walk up to a co-worker (or post on slack these days) and say "Aah! I tried X and it doesn't work", there is nothing else they can say except "what do you mean?" So provide context.

When things don’t work as we expected, we get worried and start debugging but sometime stepping back and understanding the ‘rules of engagement’ is what is needed.

All of this is easier said than done in the moment. Yes I too shake my fist at the screen and mumble stuff when things don't just work as I expect them to.

The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. — Brian W. Kernighan