When the code doesn’t work

Me: I want my code to make this text on the screen invisible. So, right here at the beginning of the function, I have code that hides that text. Everything I can do to test the code says that it’s working. When I run a check right after hiding the text, it tells me that the text is hidden, just like I want it to be. But when I run the code, the text is clearly visible, not hidden.

Me: [Spends half an hour trying all sorts of things to figure out why this clearly visible thing thinks that it’s hidden.]

Me: [Happens to look at the end of the function.]

Me: [Sees that the last line of the function makes the text visible—so the code at the beginning of the function is hiding the text, but then the last line of the function is unhiding it, and the hiding-and-then-unhiding happens too fast for me to see it when the code is running.]

Me: [Removes that last line of the function.]

The code: [Now works as expected.]


(I feel like this is yet another variant of the most common problem that I run into when coding: if I change something in the code but the change appears to have no effect, then I’m almost certainly changing the wrong thing. (Such as an old version of the file, or a version in a different directory or a different source-code client, or an uncalled copy of the code in a different place in the file, or etc.))

Join the Conversation