Why Coding Less and Sleeping More Could Make You a Better Developer
6 min read
On your journey of learning to code it's highly likely that at one point or another, you'll lose sleep over it.
Perhaps working late into the night trying to tackle a seemingly-unfixable bug keeps you awake long past your bedtime, or waking up in the early hours with syntax on your mind means you get less shut-eye than you’d like to.
Either way, coding is cognitively-demanding, requiring high levels of attention, deep conceptual understanding, problem-solving, and memory, amongst other mental processes.
Something as cognitively intense as this doesn't always make for a sound night's sleep.
But what if rather than staring blankly at the screen when you hit a snag, you try getting some sleep instead?
Let's take a look at how coding less and sleeping more could help you to become a better developer.
The Power of Sleep
Sleep is a truly incredible thing, and not getting enough can be tough to deal with.
Whether you've had a late one the night before and found it hard to focus the following day, or an early start made you feel you had woken up on the wrong side of bed, a night with poor sleep makes everything feel like more of an effort.
On the other hand, a sound night's sleep makes you feel refreshed, like you've recharged your batteries; But what exactly happens in your brain when you're asleep?
For centuries, scientists knew very little about why we sleep and what happens when we do, but in recent years, researchers have concluded that not only is it definitely good for our brains and body, but they now wonder whether there are any biological functions that do not benefit from a good night's sleep.
Of course, sleep gives your body a chance to recover and recharge, but it also serves a crucial purpose for memory and learning; two functions that are hugely important for any developer to do well.
The effect that sleep has on our memory really can't be overstated.
It has a huge impact on our ability to: (a) acquire - or take in - new information (b) store it in the brain, and (c) recall the information later on.
These three functions must occur for something to become a memory, and research suggests they're all affected by poor - or a lack of - sleep.
In Why We Sleep, neuroscientist and sleep researcher Matthew Walker points to a study where students were divided into two groups, and were then asked to study a list of facts that they would be tested on at a later stage.
After studying the facts, one group was allowed to get a full night's sleep, while the other group was kept awake by laboratory staff, so they were sleep-deprived the following day. Both groups were then given two nights to recover, before being asked to recall the facts they had attempted to learn.
Perhaps unsurprisingly, the sleep-deprived group showed a 40 percent deficit in their ability to recall the facts. They were less effective at cramming new facts into their brain than those that had slept well on the first night.
Effectively, the group that had slept well aced the exam, while the sleep-deprived group failed it.
Those of us that have tried to cram the night before an exam, only to find the facts we thought we had learned had vanished when we tried to recall them in the exam itself, can relate to this research.
So, what can this teach us?
After we learn new information, it's important to get a good night's sleep if we want to make it stick.
Sleeping is Like Pressing Save
It might sound strange, but sleeping really is like pressing a save button in your brain.
When you first encounter new information, it gets stored in the hippocampus (a short-term storage site). While the hippocampus is great for storing information for a short period of time, it's not a great place to store anything really important, as its contents are quickly forgotten.
However, when we seep, newly-acquired information moves from our short-term storage, to the neocortex, the long-term storage site at the top of the brain.
While this process isn't fully understood (the brain is pretty complicated, to be fair), it's clear that a good nights' sleep - or even a solid nap - helps us to process information and commit it to memory; a key component involved in learning.
Problem solving is a fundamental part of being a developer. More often than not, when we hit a bug we take the 'brute force' approach, typing away hour after hour making small tweaks in our code in the hope that we find the solution.
The issue is, the longer we work without finding a fix, the more mentally tired and frustrated we become, and the less likely we are to find the answer to the problem we were trying to tackle in the first place. It's a pretty inefficient way to go about it, right?
What if there was a better way? It might sound counter intuitive, but what if we take a break from our code when we can't find a quick fix, and just go to sleep instead?
Researchers at Northwestern University looked to better understand how sleep benefits daytime cognition by asking participants to attempt a series of puzzles while listening to specific sound cues.
Later that night, while they slept, participants were played the sounds associated with half of the puzzles they had failed to solve earlier that evening.
The following morning, participants were more likely to solve the puzzles that had the associated sound cues played to them overnight, compared to the puzzles that did not have sounds associated to them.
Kristin Sanders, a doctoral student and first author of the research paper, says the study suggests "people rehearse or ‘consolidate’ memories during sleep, strengthening and reorganising them".
Sanders goes on to say, "the underlying cognitive processes (in the study) could relate to solving any problem on which someone is stuck or blocked by an incorrect approach".
When you're working on a project, it's common to feel that you know what you need to know to solve the problem in front of you, but the pieces just won't fall into place.
A good night's sleep can help you to organise your memories, so you can use them more effectively the next day.
What does this mean for coders?
American Author John Steinbeck famously said, "It is a common experience that a problem difficult at night is resolved in the morning after the committee of sleep has worked on it."
Whether it's moving newly-learned information from short-term to long-term storage, re-organising existing memories, or continuing to think through a difficult problem long after we've closed our eyes for the night, the committee of sleep has got you covered.
So next time you come across a coding problem you just can't seem to solve, try stepping away from the screen and getting some sleep, you might just be surprised how well it works.
If you enjoyed this article and want to see more content about development, design, creativity and learning then follow me on Twitter at http://www.twitter.com/danielcranney .
Sources and Studies
Sanders, K. E. G., Osburn, S., Paller, K. A., & Beeman, M. (2019) Targeted Memory Reactivation During Sleep Improves Next-day Problem Solving. Psychological Science. 30 (11).
Sio, U. N., Monaghan, P., Ormerod, T. (2013). Sleep on it, but only if it is difficult: Effects of sleep on problem solving. Memory & Cognition, 41, 159–166.
Walker, M. (2017). Why We Sleep. [London]: Penguin Books.