How to Program in Your Sleep

Marianne Bellotti
4 min read2 days ago

I thought it was just me … but then I talked to a bunch of mathematicians

Image by goonerua

A year or two ago when I was working on the core compiler functionality for Fault, I got into this weird habit of programming in my sleep. I don’t mean I sleepwalked over to my computer and started cranking out API endpoints (although apparently some people also do this). I mean I would wrestle with a complex problem all day, only to give up, go to bed and wake up with the answer. Within five minutes that bug that had been driving me crazy for hours was fixed, or I had a strategy for organizing my abstractions, or a set of new ideas to test. While my consciousness was quiet and empty, my subconsciousness continued to work on the problem.

Some people describe it as dreaming a solution. That’s not the way it works for me. I don’t dream about it. I don’t have any particular recollection of even thinking about the problem. I just wake up and a solution is sitting in my mind, all queued up and ready to go.

https://www.reddit.com/r/webdev/comments/kbqc5j/comment/gfn0g05/?utm_source=reddit&utm_medium=web2x&context=3

This phenomena is so common it actually has a name. It’s called incubation and it can also be triggered by long walks, or just distracting your conscious mind with something else so that your subconscious is left alone to mull over the problem in depth. There are a lot of theories as to the how and why it works, most rely on the notion that our conscious mind can actually be a mean little shit, distracting us with anxieties and frustrations around the fact that the problem exists and keeping us from focusing on the problem itself. When that part of the brain turns off, or gets distracted by something else, the rest of the brain is free to play openly with the problem.

The other theory about why we solve problems in our sleep comes from what we believe our brains are actually doing during sleep in the first place. Sleep is when our brains reorganize our memory, finding new patterns and building up our metadata around our experiences. Some of this problem solving may actually be secondary, a consequence of a new pattern forming that immediately makes the problem look different.

Luke, read the best stories from industry leaders on Medium.

The author made this story available to Medium members only. Upgrade to instantly unlock this story plus other member-only benefits.

Access all member-only stories on Medium

Become an expert in your areas of interest

Get in-depth answers to thousands of questions about technical

Grow your career or build a new one

Marc-André Giroux

Marc-André Giroux

Sr. Software Developer

Netflix

Carlos Arguelles

Carlos Arguelles

Sr. Staff Engineer

Google

Tony Yiu

Tony Yiu

Director

Nasdaq

Brandeis Marshall

Brandeis Marshall

CEO

DataedX

Cassie Kozyrkov

Cassie Kozyrkov

Chief Decision Scientist

Google

Memo Akten

Memo Akten

Asst. Professor

UCSD

Vitali Zaidman

Vitali Zaidman

Software Architect

Meta

Camille Fournier

Camille Fournier

Head of Engineering

JPMorgan Chase

Marianne Bellotti

Author of Kill It with Fire Manage Aging Computer Systems (and Future Proof Modern Ones)