It should work! We’ve all been there. That feeling when you’ve been coding for hours and you’re almost done with a major chunk of the application. All the pieces are connected the way they should be but there’s some mysterious bug or runtime error. You scratch your head and start reading through your code, “Oh forgot a return statement!” Run the code again and get the same error. Sigh and keep reading, “Oh, I misspelled that variable name!” Run the code again and get the same error. Grind your teeth and keep reading, “This variable is instantiated inside this function and can’t be accessed in the outer scope.” Run code, same error. You scroll quickly through the file, your eyes unfocus a bit and everything starts to look the same and lose meaning. You start changing parts of the code that have nothing to do with part of the application causing the error because nothing makes sense anymore and you break more things in the process.
I wanted to spend some time talking about frustration, because it’s an emotion that is going to come up as programmers, and there are tools that can help you manage it that can save you as much time as a good recursive algorithm.
-take breath, stand up, stretch, do a push up or two to get the blood circulating -go eat a snack, a yogurt, a handful of nuts, have a glass of water -go walk around the block and get some sunshine, swing by the grocery store and pick up something for dinner -go clean the dishes
Kind of banal suggestions I know, but that’s pretty much the point. Find something to do that activates any part of the body or brain that isn’t related to critical thinking. Something automatic and repetitive like washing the dishes is a great way to give those analytical pathways in the brain a break. Standing up to stretch a bit can work wonders, even better if you can walk into another room to do it. No visual reminders of the problem that is currently stumping you, get the blood flowing and ground yourself back into your body after spending so long in the mental space. A glass of water and a light snack will get your body focused on digestion instead of critical analysis. Anything to switch gears and let those analytical parts of the brain perform an unconscious reset in the background.
The tricks used to alleviate frustration are as important as your attitude towards it. When you get caught in the “It should work!” downward spiral, your pride constructs a narrative that you are right and the machine is wrong. You know what you are doing, you know this should work, and the errors in the console become personal attacks on your ego and self worth. This triggers a defensive emotional response, and all of a sudden you’ve shifted from a cool, balanced, and constructive headspace to one dominated by imposter syndrome and a feeling of hopelessness.
Falling into that rabbithole can require a full night’s rest to properly reset from, but with a little practice and mindfulness you can realize what’s happening before the spiral has fully taken hold. Would you rather spend forty-five minutes banging your head against a keyboard or fifteen minutes outside to regain objectivity? Come back after a walk and reread the documentation for the third-party software you’re trying to integrate. I bet you missed something, and in my experience that something tends to jump out at you after a properly utilized break.