Think back to the last time you had that really tough programming problem you couldn’t crack.
If you’re like me, you may have spent a few hours trying to brute force a solution. Then, in despair and frustration, eventually you gave up for the night.
And then the next morning, you wake up and the solution is clear as day in your head. You face palm yourself, rush to your computer, implement it in 15 minutes, and all is well in the world again.
Or this — I work a problem all morning to no avail. Lunch time hits, so I take my dog for a 30 minute walk. And somewhere along that walk I’ve figured out the solution. I get back home and fly through it the rest of the afternoon.
Look, I realize I’m not saying anything particularly new or profound here. But it absolutely bears repeating because I often forget this too:
Sleeping and walking are some of the best techniques to improve your work as a programmer.
(Pro tip: don’t take your phone to bed or on your walks. Your brain needs to be fully disconnected.)
I’m no scientist or expert on how the brain works, but there is plenty of science to back it. The basic premise is that free association and fixation forgetting (letting go of what you’re banging your head on) is crucial to problem solving. Your brain can put together solutions more effectively when it’s allowed to wander.
This is exactly why “Eat, sleep, code, repeat” is such bullshit. Your brain needs to do something else from time to time (and be rested) to do your best programming.
So the next time something isn’t clicking, leave it. Forget about it. Take a walk and go grab a donut. Get 8 hours of sleep. Your brain will do the heavy lifting and tell you when it’s ready to solve that problem.