HACKER Q&A
📣 _448

How many of you dream in code or find solution to a problem in sleep?


This use to happen to me once in a while, but recently the frequency has increased considerably.

Wondering how many on this forum have experienced finding solutions to problems while asleep.


  👤 Kaimana Accepted Answer ✓
I've never coded. I'm a boatbuilder and marine architect (that's a very specialized kind of hardware engineer in startup language). We have "coding problems" too: how to make a boat so it doesn't kill the people who take it out to sea.

Different parts of a boat need to do different things, and often your next boat can't be designed by copying your last one and making things smaller or bigger; you need an entirely new concept for a new function.

So when I sit and "think" about the problem, trying to make progress on it, I usually spin my wheels and get nowhere. I can't draw, I can't write, because I'm forcing it. Trying to make money thinking, right, and it just won't come.

But often, later that night, I'll have a fully-formed picture of the solution come into my head, of the thing that was puzzling me back in the daylight. I'll get up, turn on the light, go to my desk, and sketch the thing out, with explanation about what the different chicken scratch lines are. I put my mouse on top of it so my cats don't knock it onto the floor, because in the morning I've complete forgotten I even woke up and drew it. The next morning, there's my solution sitting on my desk.

So faced with problems demanding solutions, I've learned to just relax and be the space that the solution can come into.


👤 rapjr9
I spent many years solving difficult code problems as part of a research group. One of my standard techniques for solving the toughest problems was to gather as many facts as I could and then sleep on it. I'd find myself not reviewing the code, but reviewing the facts in my sleep, and when I'd wake up I'd have figured out the problem or at least have figured out how to get more information to solve the problem. I'd often wake in the middle of the night to write down these insights or write them down first thing on waking.

👤 xaedes
I had a (not very long) time where I was heavily into making electronic music. After a while I dreamed in music. It actually scared me a bit as music was all there was. Nothing else. Not even thoughts. Only the sound of music. Yet it did not help me making more or better music. It might have if I would have continued longer, but I stopped some time after that, starting to chase another passion...

But the music dream was a very unique and memorable experience.

Code and programming sometimes plays part in my dreams, sometimes I just continue to work on the program I worked on before going to bed. At least that is what I remember after waking up. Did not bring me any great breakthrough so far. But continuing the real code the next day goes lighter, sometimes.

The feeling of code dreams is not as weird as from the music dream. Maybe I am just used to that from being in the flow in my waketime. When in the flow, code, or the abstract problem I work on, is all there is - similar to the dream. It also has the bonus that I can actually get things done and they persist. No wake-up and puff-all-gone.

To conclude I would liken code dreams to a light version of prototyping. You try out some stuff, throw it away and (hopefully) do better the next time you work on similar stuff. Not that I can consciously remember the lessons learned, but it trains intuition and the feel for handling problems.


👤 rogual
I'd always have this one where I'd be half-asleep in the morning, thinking about a person, event or place, and I'd be confused about whether it was a class or an object. My brain knew that everything has to be one or the other, it just couldn't quite seem to figure this one out... or that one...

Never happens anymore. Maybe my programming style changed, or I just got better at not thinking about work too much outside of work hours.


👤 asicsp
The earliest I remember is during college (around 2008-9). I had been solving lot of exercise problems within a short span and then had a dream. Found a bug in one of solutions.

I've had a few since then, but not many that left an impression. One was automated test generation during my job as a test engineer for Digital Signal Processing chip (fitful sleep with unending ideas about generating tests).

Another was last year, after I had answered a question on stackoverflow. It was good enough to warrant a blog post: https://learnbyexample.github.io/mini/dreaming-solutions/


👤 msarrel
I work at a technology company and I have at various times been in an evangelism or a technical marketing role. I know it's not the same thing as dreaming in code, but I frequently wake up in the morning with a great idea for something to write. This happens more often when I go to sleep thinking about what I need to write the next day. It feels like my active mind let's go and my subconscious mind gets creative. This did not happen to me in college or grad school, so I suspect it is related to the stress I put myself through thinking about what I need to write the next day.

👤 Diggzinc
I've recently read the book named "Why We Sleep: Unlocking the Power of Sleep and Dreams" by Matthew Walker[0] and he explains in good detail how and why this happens.

This is not something particular peculiar about just certain individuals but actually is, in fact, one of the functions of sleep.

I would vividly recommend anyone to read it, in order to improve their own life overall, that includes memory recollection + reconciliation.

[0] https://www.goodreads.com/book/show/34466963-why-we-sleep


👤 dokem
I have dreamt in code, yes. Sometimes it would feel like I was solving something but it was either a meaningless sensation or I would forget it. I don't code in my free time or take work home anymore so it doesn't seem to happen now. Now I dream in having a social life where I vividly feel content. Solving that problem is more important now so it occupies my subconscious.

👤 tighter_wires
This has happened to me on a few occasions, once during SAT prep in highschool, I woke up with the answer to a hard math question a friend and I had been stuck on. I’ve also dreamt in code after a long week at work - the code was mundane and just a reiteration of what I’d been doing during the week, and didn’t involve any interesting breakthrough solution or anything.

👤 ramoz
I have, but only when Ive stayed up way too late coding, or coding over multiple days without much sleep. It’s never a good thing really.

👤 Phreaker00
I've long ago realized that going to sleep with a prepared mind (occupied by the problem) would often result in a working solution when waking up in the morning.

Once read an article that research showed that studying before sleep would increase retention 30% compared to studying in the morning. So at night your brain is actively working and you can take advantage of that.


👤 quickthrower2
I dream in code if I am learning something new and hard - like Haskell, but I never find a solution though!

👤 iscg
I did and it was significantly affecting my quality of life. I realized that if I stopped coding or thinking about work around 5 hours before bed time it would stop, it is a little hard but it is so worth it.

👤 Jxl180
I don’t think I’ve ever dreamt in code, but I had a Tetris phase and I absolutely dreamt (and day dreamed) in Tetris.

In fact, dreaming (and thinking) in code (or any activity) is known as Tetris Syndrome or Tetris Effect.


👤 BlameKaneda
I know of someone who had a nightmare about being stuck in an infinite loop.

I rarely have code dreams, but when I do it's usually rows of IDE text that I can't make out from a distance.


👤 taf2
I think maybe 15 years ago I did… I just find now days maybe the problems are less hard… but just a good night sleep and things come together much nicer in the morning

👤 hideo
For a counterpoint I have never once dreamt in code. I have woken up fresh and been in a better state to solve problems but I’ve never woken up with a solution in mind.

👤 ashwanijanghu
I did not once but multiple times. This has become one of the points in my mentorship advice as well.