The first time I dreamt in code, I awoke exhausted and concerned for my mental stability. I was slightly feverish, fighting the effects of an oncoming cold, which mucked with my brain chemistry and ruined all chances of a normal night’s sleep. I was also in the middle of a long, stressful week at work, where I was pulling long hours and immersed in a single front-end development project. I would later come to comprehend the subtleties of what happened that night, but at the time could only understand it in a literal sense: I had a dream entirely about, within, and in the form of code. Just code.

It felt like I was trapped in a text editor with chunks of text flying across my field of vision. Variables, arrays, objects, conditional statements: that’s all I could see. All night. And I wasn’t just a passive observer in the dream, I actually scripted logic and built functions for hours, and all of it kind of made sense. I was preemptively tackling problems that I subconsciously anticipated to come up the following day. 

It wasn’t quite a nightmare, but it was far from pleasant.

Despite the disruption in my usual sleep pattern, I finished the project and moved onto other things. It’s hard to say whether my first code dream improved my contribution to that project in any measurable way, but the morning after brought a feeling of preparedness for solving the problems I would face that day, like I had been practicing. I’ve been having many more experiences like this over the past few years, where my brain continues to work on the problem-of-the-day during my dreams, and now I’m pretty sure they’re turning me into a better developer.

The science of dream learning

Before I tell you how I’ve used my dreams as a space to practice programming skill, I should point out that a lot of literature on dreaming drifts into the pseudo-scientific, perpetuated by popular culture and a general misunderstanding of how the subconscious mind works. Concepts like dream signs, visions, and spirit guides have obscured some of the real scientific research that exists on dreams, as well as the genuine scientific basis for some of the pseudoscientific stuff. For example, one idea from Chris Nolan’s film Inception—that you could use a “totem” to tell you whether you’re awake or dreaming—is based on the real phenomenon where your sleeping mind has trouble believing you’re dreaming unless you can trigger one of the natural giveaways (here’s an example: count the fingers on one hand during a dream. You’ll probably count more than five, because the part of your brain that instinctively knows the right answer is asleep). 

Despite the pseudoscience, researchers have been generating some pretty cool insights on dreaming: a few experts have even shown how your mind can continue to learn and develop physical skills while you’re asleep. Dr. Daniel Erlacher recently conducted an experiment that demonstrated exactly that: his test participants practiced a simple task while dreaming and showed significant improvement when performing the task in the real world. With enough discipline, anyone should be able to repurpose their sleeping hours for improving a skill or solving real-world problems.

But how does it work?

Neurologists have known for a long time that the brain uses sleep cycles to continue understanding the previous day’s experiences and work through problems. The trouble, though, is that so few people can naturally remember their dreams, and fewer still can naturally nudge their subconscious in a desired direction. There are techniques for honing these exact skills, but I won’t elaborate on them here (instead, this is an awesome resource). I will, however, share some of the things I’ve learned and experienced while dreaming in code, which will hopefully encourage you to try it with any skill.

Abstract the problem. It’s hard to explain, but the code in my dreams isn’t an actual programming language, I just know that it is code, and I know what it represents. Said another way, I would never be able to copy what I remember from my dreams directly into a text editor and expect it to work. When I dream in javaScript, I know it’s javaScript and I know what it means, but it’s actually just gibberish. If I were to try to read it line-by-line, it wouldn’t make any sense at all, but if I think about it conceptually, it’s obvious. Dreaming this way is actually pretty useful to me, because it forces me to code abstractly, without worry for syntax. The code just becomes a placeholder for the logic and functionality behind it, which I can translate into the real thing later (if I can remember it). 

Your brain is bored during sleep, so put it to work! So much of my day is spent typing, clicking, drawing, and swiping. I rarely sit down to just think about a problem, and when I do, I keep it to a few minutes. Imagine if you took a bulk of your day to recline back in your chair, stare at the ceiling, and think. You could sort through a problem, flesh out an idea, or imagine something brand new. If that idea appeals to you like it does to me, you should realize that the time you spend sleeping is perfect for that. Hell, your brain already does it… the trouble is, we let our subconscious minds dictate our dreams, and it would rather we spend the night battling personal demons, rehashing embarrassing events, and living out fantasies. Wouldn’t it be great if you could get your sleeping mind to focus on one thing for a few hours? Even better: let’s get it focusing on stuff that really matters, like achieving our goals, honing our skills, and becoming better versions of ourselves.

Develop muscle memory (without moving your muscles). A lot of skills require repetition to develop. Mastering a musical instrument is the perfect example: you might totally understand how a piano works in theory, but until you’ve had plenty of practice on the keys, you won’t become a good player. The same applies in my profession, and most of my hobbies. The point is that dreams are the perfect venue for rehearsing and practicing a skill—even a physical one like playing piano, which requires muscle memory and repetition. It may be hard to believe that dreaming can transfer to muscle memory, but the research is there: it actually works. Even if the effect is just a result of greater confidence stemming from familiarity and practice, it’s pretty amazing to think that we could use the hours we spend sleeping to become more effective at anything. 

So, any wannabe oneironauts out there?

If so, there are a few places you can start. Use a journal to log your dreams every night (keep it by your bed, and write down everything you remember as soon as you wake up, otherwise you’ll forget it). Also, learn some techniques for accomplishing lucidity in dreams and practice them nightly. Lastly, if you have a problem to work through in a dream, work on it for an hour before you go to sleep, and try to make it the last thing you think about when you doze off. 

It’s been several years since I first dreamt in code, and I remember truly hating that it happened. I correlated it to being unable to put down my work, or an incapacity to “turn off my mind” and relax. Years of dreaming in code later, I realize that the opposite is true: dreaming in code is exactly how my mind relaxes. I start puzzles during the day, and in my sleep I solve them. That resulting feeling of completion, that sense of fulfillment—it offers rest. And gives me energy. Exactly what I need from eight hours of sleep.