DEV Community

Cover image for Your Best Code Might Be Written While You’re Not Coding
Khali Sollis
Khali Sollis

Posted on

Your Best Code Might Be Written While You’re Not Coding

What neuroscience reveals about movement, creative thinking, and why stepping away from your screen may help solve difficult problems.

The bug that followed you out the door

(The following scene is fictional. No developers were harmed, though one was mildly humbled)

You’ve been staring at the same function for two hours. You’ve read the documentation twice, the second time more slowly, as if the problem were your reading speed. You’ve added logging, then logging for the logging. You’ve questioned the architecture, then your career, then whether the race condition might be personal.

Eventually you go outside. Not as a strategy. As a surrender.

Six minutes later, waiting at a crosswalk, it arrives: the cache isn’t stale, it’s being warmed by the wrong job. You can see the whole thing. Your laptop, meanwhile, is three blocks away, asleep and smug.

If you’ve ever had an idea arrive after stepping away from a stubborn problem, you know the peculiar timing. The interesting question isn’t whether it can happen. It’s why it sometimes happens just after deliberate searching has stopped, and what that says about how thinking works.

What happens when scientists ask people to walk?

In 2014, Stanford researchers Marily Oppezzo and Daniel Schwartz ran four experiments on a deceptively simple question: does walking change how people generate ideas?

In the first, 48 students sat at a desk facing a blank wall and completed two tasks. One was the Alternate Uses test: list as many uses as possible for an object, like a button or a tire, in four minutes. The other was the Compound Remote Associates test: find the one word that links three others (“cottage, Swiss, cake” → cheese). Then they stepped onto a treadmill, also facing a blank wall, because science is glamorous, and did new versions of both tasks at a comfortable pace.

The results split cleanly. In the first experiment, 81% of participants generated more creative responses while walking than while sitting, counting only ideas that were both novel and appropriate. Across participants, creative output rose by roughly 60% on average. Walkers talked more overall, but the proportion of their ideas that counted as creative also rose, so the effect wasn’t simply a matter of volume. On the remote-associates test, the one with a single correct answer, walking made performance slightly worse.

That asymmetry is the most useful finding in the paper. Walking didn’t make people smarter. It seemed to loosen the flow of candidate ideas while mildly hurting a tightly constrained search for one right answer.

Later experiments tackled the obvious objections. Practice didn’t explain the effect: people who sat twice didn’t improve. People who walked and then sat down kept much of the boost. Walking outdoors worked too, although nine participants had to be excluded after being ambushed by bikes, loud trucks, and, in one case, their own phone, which may be the most realistic detail in the literature. In the final experiment, participants generated analogies while sitting indoors, walking on a treadmill, walking outside, or being pushed outside in a wheelchair. For the highest-quality novel analogies, walking mattered and scenery didn’t. For novelty defined more loosely, walking and being outdoors each contributed separately.

The caveats are part of the story. The last two experiments had about ten people per condition. Participants spoke their answers aloud to a friendly researcher, and the authors themselves asked whether the effect would hold on a solitary walk. Follow-up studies are mixed. A 2017 study found that walking beat standing on two different idea-generation tasks. A 2018 study, in which 32 students walked for 15 minutes before testing, found no significant difference from sitting on any creativity measure. And naming unusual uses for a tire is not designing a schema migration. These studies measured idea generation in a lab, not programming performance anywhere.

Your brain has more than one way to work

The split between generating and evaluating matters because software work constantly alternates between them. Sketching three approaches to a rate limiter is generative. Confirming that the one you chose doesn’t double-count requests under concurrency is evaluative. Both are thinking. They are not the same kind.

Neuroscience offers a suggestive picture, not a definitive one. Psychologist Roger Beaty and colleagues reviewed imaging studies of tasks ranging from divergent thinking to poetry and musical improvisation. They noted a recurring pattern: two brain networks that often work in opposition tend to cooperate during creative tasks. One is the default network, linked to internally directed thought such as memory and imagination. The other is the executive control network, linked to goal-directed attention. A 2018 study of 163 people found that connectivity among default, salience, and executive systems predicted individual divergent-thinking scores, a pattern that held up in independent datasets.

These findings are correlational. They describe brain activity and individual differences rather than proving a mechanism, and none of them involved walking. Networks are also not departments with job descriptions. There is no creativity center, no right-hemisphere art studio, no switch that boosts creativity by turning focus off. If anything, the evidence suggests creative thought involves coordination between spontaneous and controlled processes, not the absence of control.

Why the shower gets all the good ideas

The shower has never installed a compiler. Yet it gets credit for a remarkable number of fixes.

Researchers call this incubation: setting a problem aside before returning to it. A 2009 meta-analysis by Ut Na Sio and Thomas Ormerod, pooling 117 studies, found a real but conditional effect. Open-ended, divergent-thinking problems benefited more than insight puzzles with a single answer. Longer preparation before the break was associated with larger incubation effects, which suggests the work done before stepping away matters, not just the break itself. The break’s contents mattered too. Demanding activities tended to shrink the benefit, while for one class of word-based insight problems, light activity beat pure rest.

A 2012 experiment led by Benjamin Baird seemed to explain why. Participants worked on unusual-uses problems, then spent 12 minutes on one of three breaks: a demanding memory task, an undemanding one, or rest. A fourth group took no break. The undemanding group improved substantially, but only on problems they had already seen. They also reported more mind-wandering, without reporting more deliberate thought about the task. Mind-wandering, it seemed, was doing the work.

Then came the replication attempts. In a 2016 series of studies, mind-wandering measured during the break didn’t predict creative performance. A later conceptual replication with 443 participants found no evidence that mind-wandering during an incubation break improved divergent thinking. Stepping away can help. The claim that a wandering mind is what makes it help is on much shakier ground.

Why breaks sometimes work remains unsettled. Candidate explanations include escaping fixation on a wrong approach, continued associative processing, and picking up new cues. These are hypotheses. Nothing here shows your unconscious quietly closing tickets while you rinse out shampoo.

A walk is not a debugger

Back to the crosswalk. The cache-warming idea felt like certainty. Feelings of certainty are cheap.

A walk might help you consider that the bug lives in a background job rather than the request path. It cannot tell you whether that job actually runs before the cache is read, whether your fix creates a thundering herd, or whether the elegant refactor you imagined survives the forty edge cases your tests encode. Recall the remote-associates result: the condition that helped idea generation slightly hurt the task with one correct answer.

The useful model isn’t “focus bad, wandering good.” It’s a cycle. Sustained attention loads the problem: reading traces, building a mental model, ruling things out. A change of mode may let alternatives surface. Then focus returns to test them. Skip the first phase and the walk has nothing to work with. Skip the last and you’ve merely had a nice idea.

The productivity paradox

Here’s the uncomfortable part. Most workplaces can see only one of those phases.

Typing is visible. Commits are countable. Green status dots are reassuring. Twenty minutes spent staring out a window and reframing a problem looks, from outside, exactly like twenty minutes of not working.

Researchers who study developer productivity have pushed back on single-metric thinking. The SPACE framework, from Nicole Forsgren and colleagues, argues that productivity spans several dimensions and can’t be captured by activity levels alone. That doesn’t prove walks make teams faster; nobody has shown that. It does suggest that “looks busy” is a weak proxy for “is making progress.”

Picture two developers. One types steadily all afternoon, iterating on the same wrong assumption. The other walks for twenty minutes and comes back with a better hypothesis. Neither outcome is guaranteed, and this is an illustration, not data. But a culture that rewards only the first pattern is measuring motion and calling it thought.

When stepping away doesn’t help

Sometimes a walk is just a walk.

If you’re missing information, like an undocumented API behavior or a log you haven’t found, no amount of incubation will conjure it. If the work demands careful verification, such as reviewing a security-sensitive change or reasoning about a memory model, nothing in this research suggests a stroll will help. Some problems want a profiler, a teammate, or a methodical bisect through commits.

The effects themselves are variable. Incubation depends on the task, the preparation, and the break. Single bouts of exercise tend to produce small cognitive effects that shift with duration, intensity, and task type. Those short-term effects are a separate question from the long-term benefits associated with regular physical activity, which come from a different body of research. None of it adds up to a prescription.

The best idea may arrive after you close the laptop

Our fictional developer walks home, opens the laptop, and writes a failing test for the cache-warming theory. It fails exactly as predicted. The fix takes eleven minutes. This time the theory was right. Next time it might not be, and the test will say so.

The walk didn’t solve the bug. It changed the developer’s relationship to the problem long enough for a different explanation to surface. The solving still happened at the keyboard.

Maybe the mistake isn’t that developers spend too much time thinking. Maybe it’s that we’ve defined thinking so narrowly that we only recognize it when it’s typing.

Sources and Further Reading:

Walking and creative thinking

Oppezzo, M., & Schwartz, D. L. (2014). Give your ideas some legs: The positive effect of walking on creative thinking. Journal of Experimental Psychology: Learning, Memory, and Cognition, 40(4), 1142–1152. https://doi.org/10.1037/a0036577
Zhou, Y., Zhang, Y., Hommel, B., & Zhang, H. (2017). The impact of bodily states on divergent thinking: Evidence for a control-depletion account. Frontiers in Psychology, 8, 1546. https://doi.org/10.3389/fpsyg.2017.01546
Frith, E., & Loprinzi, P. D. (2018). Experimental effects of acute exercise and music listening on cognitive creativity. Physiology & Behavior. https://doi.org/10.1016/j.physbeh.2018.03.034

Incubation and mind-wandering

Sio, U. N., & Ormerod, T. C. (2009). Does incubation enhance problem solving? A meta-analytic review. Psychological Bulletin, 135(1), 94–120. https://doi.org/10.1037/a0014212
Baird, B., Smallwood, J., Mrazek, M. D., Kam, J. W. Y., Franklin, M. S., & Schooler, J. W. (2012). Inspired by distraction: Mind wandering facilitates creative incubation. Psychological Science, 23(10), 1117–1122. https://doi.org/10.1177/0956797612446024
Smeekens, B. A., & Kane, M. J. (2016). Working memory capacity, mind wandering, and creative cognition: An individual-differences investigation into the benefits of controlled versus spontaneous thought. Psychology of Aesthetics, Creativity, and the Arts. https://doi.org/10.1037/aca0000046
Murray, S., Liang, N., Brosowsky, N., & Seli, P. (2024). What are the benefits of mind wandering to creativity? Psychology of Aesthetics, Creativity, and the Arts, 18(3), 403–416. https://doi.org/10.1037/aca0000420

Brain networks

Beaty, R. E., Benedek, M., Silvia, P. J., & Schacter, D. L. (2016). Creative cognition and brain network dynamics. Trends in Cognitive Sciences, 20(2), 87–95. https://doi.org/10.1016/j.tics.2015.10.004
Beaty, R. E., Kenett, Y. N., Christensen, A. P., Rosenberg, M. D., et al. (2018). Robust prediction of individual creative ability from brain functional connectivity. PNAS, 115(5), 1087–1092. https://doi.org/10.1073/pnas.1713532115

Exercise and cognition

Chang, Y. K., Labban, J. D., Gapin, J. I., & Etnier, J. L. (2012). The effects of acute exercise on cognitive performance: A meta-analysis. Brain Research, 1453, 87–101. https://doi.org/10.1016/j.brainres.2012.02.068
Erickson, K. I., Hillman, C., Stillman, C. M., et al. (2019). Physical activity, cognition, and brain outcomes: A review of the 2018 Physical Activity Guidelines. Medicine & Science in Sports & Exercise, 51(6), 1242–1251. https://pubmed.ncbi.nlm.nih.gov/31095081/

Developer productivity

Forsgren, N., Storey, M.-A., Maddila, C., Zimmermann, T., Houck, B., & Butler, J. (2021). The SPACE of developer productivity. ACM Queue, 19(1), 20–48. https://queue.acm.org/detail.cfm?id=3454124

Top comments (0)