Wednesday, 4 September 2013

Why you should check your variable names, and then check them again

Because it's the smart thing to do.

For real. It seems that the trickiest bugs that I have encountered are the ones that don't throw an exception in your face. You get so used to your own code that you kind of just assume that everything has been typed correctly. Sometimes that isn't the case.

I've been trying to fix a bug related to my silly ice bergs not relocating properly. Basically, after they relocated, a boolean was changed to true saying that they are currently respawning, but when they passed a certain value on the x axis, this is changed to false. However, instead of checking the ice berg array, I was checking a completely different array. Rookie error.

I don't know; the code works now.

Bloody hell.


  1. These kinds of mistakes are often the hardest ones to spot, because when you read the code you see the value that you expect to see, not what is actually on the page. Sometimes I read the code backwards to force my brain to make sense of each word rather than return what it "thinks" should be there.

    1. Exactly. I've had my fair share of bugs that have needed to be fixed with logic, but your eyes get so used to reading the same code that you brush over some of the real problems!