Ask HN: Does anyone dream of code?

104 points by rs86 ↗ HN
I have been having this problem lately. When I close my eyes and try to sleep my mind wanders and soon enough I am thinking about code, programming mentally. And I wake in the middle of the night and I am still mentally coding in a semi hypnotic state. I have slight OCD if that matters. Does any one feel the same? It is as if my mind never turns off.

145 comments

[ 7.3 ms ] story [ 466 ms ] thread
This is true for everything in life. Do some thing alot, and your mind will start processing it while you are asleep.

I used to have such dreams about EverQuest. So I eventually realized I should play less :P

It's called the Tetris Effect, read: https://en.wikipedia.org/wiki/Tetris_effect

Yup, I had the same for Jedi Knight, Counter-Strike, Left4Dead. With Left4Dead I had it particularly bad, when I would walk to school in the morning - still half asleep from playing until late the night before, I would "hallucinate" the sounds of the game.

Even though I stopped gaming somewhere during university, I still have dreams about those games every now and then.

OT: Just like other's in this thread, I have dreamed about code as well, with a similar frustration to wake up knowing the beautiful solution was all imaginary :-)

First and most intense time this ever happened to me was from playing the origin Alpha Centauri. It was ultimately a deeply uncomfortable experience.
I must have had the literal tetris effect. I played so much (competitively) I would dream of the patterns and pieces all the time. That's when I knew I was playing too much.
I sometimes do. It is particularly satisfying when I debug (correctly!) the code in dream which I struggled to debug while awake.
Yep. My subconscious often gives me very interesting "left field" type problem solving/troubleshooting advice during my programming dreams.
This is not unusual. The brain processes and organizes information when we sleep, just that we don't all usually remember this happening.

I find that I tend to think about things in my sleep on three occasions:

1 when the activity is new

2.when I am sufficiently stimulated and excited by the material.

3. when I am worried or upset

This 'dream state'used to occur to me in the past when I actively played chess, when I was in school studying for exams and nowadays when I'm struggling with (and mastering) a new concept or paradigm in programming. Recognizing it for what it is - a process of deep archiving and reorganization, I have come to embrace it and even be happy when it occurs, since material I have processed in this way terms to be deeply ingrained in my memory for longer.

I do. But it doesn't happen very often, and I don't hate it.

The clearest memory I have, is when I was 15, debugging some hacky PHP codes for days still unable to find a solution. I dreamed that piece of code and suddenly wake up with a fix, it was a pretty nice feeling.

Also an year ago I started learning Haskell, despite reading a lot of tutorials I wasn't able to understand what a monad is. One day I woke up and find myself understood the concept. I don't remember the content of the dream, but it was a sweet dream and I slept longer than usual.

I am not sure if I have OCD, but I like coding so dreaming code is not an issue for me.

I can't read in my dreams. I'm able to dream that I'm reading but the whole understanding of what the text actually should transport isn't there.
In my first years of college I was a semester behind. I made up for that in 2 weeks of Christmas break.

That was the first and last time I dreamt of Java.

Yes, this is quite common.

Different types of code dreams are common too - code nightmares where you get caught in small, infinite loops or are unable to escape oscillation between a small set of bad operations

Or happy code dreams where you float above the system and observe high levels of interaction and execution, watching data flow like water, and execution happen rythmically like beats of music.

Yep. I love it when that happens. Happens especially when writing complex code instead of just rattling off CRUD. The best time was when I worked for months on a Prolog project for uni, every day, all day with very complex concepts to crack. During the day when I went outside, my brain transformed everything in Prolog clauses; cars, roads, houses, bikes, people talking to me. And at night my dreams were in code as well. I now have it when doing embedded code or game code.

Edit: Come to think of it, this 'free shrooms' experience is reason enough to not do CRUD apps :)

Yes, but not in the literal sense for me. I never see any text or code but rather some abstract version of the problem I'm trying to solve. I dislike it to be honest, it makes me feel like I'm not getting any rest, especially when I wake up in the middle of the night from a code dream only to continue in that loop while I'm half awake.

One time I went to sleep after starting a take home code test for a job interview; I woke up a few hours later having some intense dreams about it and ended up knowing exactly what to do. I finished it at 4am. I didn't end up getting the job, but they said during the interview they really liked the code.

Would you mind sharing why they (said they) ultimately chose not to extend an offer? Just curious about an anecdote from a hiring/recruiting perspective.
They never gave a reason. That said, I felt like the interview with my potential team mates (one of the 3 interview rounds that day) really did not go as well as I would have liked. I could have done better describing my current work and projects. We did some whiteboard design question and ran out of time, looking back I could have done a lot better on that had I put more thought into it. I'm not bitter or anything, it was not my best in person interview by a long shot.
Only when deeply immersed into a problem. Day to day work doesn't really get it going for me, but if its something challenging I'll see all kind of code in my dreams, I've woken up with 'aha' moments too.
I occasionally do, but it always seems to take the form of finding a really good solution to a horrible bug. Then I'll wake up full of joy at having fixed the bug only to realise it was one entirely imagined during my dream.
I have written code practically every day for the last 20 years. No, I never dream about coding.
Yep, and it's not pleasant when you're lucid enough to know you're dreaming, but not lucid enough to be able to reason properly. It's just a general feeling of trying to solve something, without any payoff.
I've had several experiences of pointlessly struggling with a dream computer, or a more abstract sort of programming-flavoured dream puzzle.

That's where you want to get lucid enough to realise that struggling with the problem isn't a worthwhile pursuit now, and go do something fun instead :)

I try not to write code for about an hour or so before going to bed. I find that if I work on code, especially a complicated problem, I will dream about finding a beautiful solution (without actually seeing or remembering what I do). It's really annoying to wake up and realize it was all just a dream.
I never really dream of code, but I did have a funny dream of me writing something and trying to get girls to check out what I wrote. I was like, "hey ladies, check out this code"
I think that's # 5 in "Top 10 Worst Pickup Lines ever"... ;)
Sometimes if I've been doing a lot, also sometimes I have dreams where the dream is just code scrolling in front of my eyes. This second type of coding dream generally happens if I'm doing more than 10+ hours a day of a very verbose language.
I started out in system administration and network engineering before switching to programming. I once had a dream that my cigarette needed an IP address before I could smoke it.
you have to issue before you can consume
(comment deleted)
I had a similar dream about my pants once.
I remember waking up in the middle of the night and trying to call the remote control. (Most times I sleep with the TV on)
I think I am gonna write a Chef recipe to automate that, so we don't have to worry to assign those IP addresses, if I was you I would switch to IPv6 though
When I go to sleep after having worked on something complex and didn't fully resolve it, I'll almost always dream about trying to solve it. Sometimes I see code, sometimes it's more abstract, but it's always disconcerting. My wife says I mumble things like, "I'm pretty sure 'also' is a keyword unless I'm losing my mind and need to check the documentation"
The worst cases for me are with math-heavy problems. I'll see code mixed with shapes and graphs. The mornings suck, because you wake up knowing you were only half-asleep.

That's why I like to play some easy games or read a book 1hr before going to sleep. Sometimes they induce creativity though and are counter-active.

I find myself dreaming in code far more frequently if I've left a problem unresolved. I never end up finding resolution in sleep though, and the problem I'm dreaming isn't usually related to what I'm actually working on. It's more like an exercise in working out the logic behind some kind of dream action, like walking or turning a door handle. I'll get stuck in a loop and go over it all night long trying to understand why is this not working!
In CS 101 I spent all night working on my final homework, walked into class, put the printed solution on the professor's desk, sat down in a desk right in front of his and fell asleep.

I dreamt about the homework problem, and realized I had made a mistake. I immediately woke up, grabbed the paper, and made the correction. The whole class burst into laughter, but the professor didn't seem disturbed. Later he told me something like that happens every few years (he's been teaching for 30).

(comment deleted)
I've been doing this for 30 years. Why? Because I work in such a way to make it happen. What you call a problem, I embrace as a gift.

Of all the things I've discussed here at Hacker News over the years, this is probably the #1 subject. Most programmers have the opposite problem of you: they have trouble turning their minds on.

I always turn my computer off several hours before bed. The last thing I do every night is review hard copies of code with a red marker. Many nights I dream of my project/code. Sometimes I even jump up in the middle of the night and go to my computer, write down my thoughts, or lately, voice record them.

Sometimes I am incredibly grateful for the "gift" I've received from "outside myself" in the middle of the night. Other times I'm annoyed. For every cool insight, there are many false positives: What was I thinking? But the positives far outweigh the negatives.

I don't know why this works, but I can't imagine accomplishing all I do without it. Many programmers struggle for years to turn this "mind CRON" on. You already have the gift. I suggest you find a way to embrace it and turn your lemons into lemonade. You don't have a problem; you have a gift. Make it count!

My original HN post: https://news.ycombinator.com/item?id=191275

Also #49 here: http://v25media.s3.amazonaws.com/edw519_mod.pdf

A lot of programmers I respect like to work on printed out code, and it's something I enjoy as well. Furthermore I'd love if we could work completely offline, with pen and paper.
> Furthermore I'd love if we could work completely offline, with pen and paper.

Why is that? I loathe writing code on paper, seems like it'd be a serious regression.

No idea, I just enjoy paper and whiteboards more, I feel more creative as well. Also the fact that you're cutting out distractions.
Really?

I have the exact opposite view. I love writing it my code on paper. It makes me feel like the creative part of the equation while I leave the 'mechanical' computation to the dumb machine. Debugging and understanding difficult code samples is easier too.

I once read that Knuth(?) never used a computer and wrote everything on paper for his sectetary to type.

I write tons of pseudo-code on paper and it helps me organize my thoughts far better than I can do on the computer (maybe I haven't found the right tools). I seem to solve more complex problems quicker too on paper (ymmv of course).
I personally don't write literal code on paper very often, but I draw workflows, interactions between pieces of code, thoughts and notes that I then refer to when coding. I spent about 4 hours the other day writing in my notebook working through a large refactor. I don't think I've written so much in such a short time since taking tests in school and I am sure the paperwork saved me a few days of stumbling around.
More coders ought to try weaning themselves off of syntax highlighting and inverting their terminal colors to dark on light, document-writing style.

If you don't need the training wheels and you're not a hacker in a movie, I think you'll discover over time that it is a sweet sweet liberation to be free from the ball and chain of syntax.

I could not disagree more. I often have to write without syntax highlighting at work, and there are zero positives and many significant negatives. It's not there as "training wheels" or to look pretty, it's there to help you avoid trivial mistakes and easily navigate through the code. There was discussion here recently about why we still edit code as text rather than as a tree, and syntax highlighting helps bridge that gap slightly, so you can think of the code as a tree rather than a long series of meaningful letters.

Seriously, have you tried this for more than a few minutes? I've been doing it for a year and a half and I've never seen any benefit. You're only "free from the ball and chain of syntax" until you try to run the code, when you realize the syntax is still there, and you're only "free" from being able to clearly see it.

Yes, I've been doing this for at least a couple years. I've been writing various kinds of code for money since 1995, and no change has ever been as helpful to me as this one.

It's just a suggestion. Not everyone will like it or agree to seriously try it. I don't think it would necessarily work well for someone who's forced to use a certain editor or configuration at work, for example (and probably continues to rely on highlighting elsewhere outside of that job, preventing the mode shift from settling in).

But I think a good many developers who haven't considered this might discover as I have that it helps them to be calm and focused on higher problem-solving at the levels that matter to them. It really is liberating to read and write code more broadly as a meaningful language rather than just fitting and stacking bits and pieces together. You might reasonably claim you can just ignore the highlighting at will, but I and others have discovered after making the move (and really giving it time to set in) that we didn't realize how much the highlighting anchored our thinking to syntax.

I've had no more trouble at all preventing or finding bugs without highlighting than I did before. Also, while I've never used one I know that there are syntax-aware editors (or probably plugins for all the usual editors) that will show you broken syntax without drowning your code in syntax color.

Out of curiosity, what languages are you using when you do this?

As a primarily Python and Haskell writer, I have no idea what you're talking about with this "unchain your mind from syntax" stuff- though I guess that in Python the syntax may be so expressive as to be no cognitive restraint, and in Haskell binding your thoughts with syntactical structure is the point.

Just Web really -- JavaScript, SQL, some bash, a little less awk, extremely rarely Perl, and a lot of the dreaded PHP.

In principle I could imagine some languages might exist in which the concerns of developers are so confined to the smallest language bits and pieces -- at the expense of bigger-picture concerns -- that the drag of ever-present syntax cues is less of a drag.

But even from what I've seen of Haskell I can't imagine wanting to have those cues in my face all the time, unless I'm either learning the language or at my wits end trying to locate a (maybe) syntax bug ... in other words, when I'm not really writing or reading code. If anything, its proximity to math might make me more eager to be free of those cues.

I think in just about any significant code-making effort, we'll need to be able to think clearly about the meaning and intent of chapters, pages and paragraphs (and maybe sentences) without hundreds of little tethers constantly reminding us about commas and parentheses and subject-verb agreement.

All I can say really is that I had no idea how much of a drag those syntax cues were until I got used to being without them. Nobody has to do it just because it worked for me (and others). It's just a suggestion.

I've often thought about coding with a touchscreen and stylus- could be the best of both worlds. But though applicable hardware exists, such an IDE still doesn't, as far as I know.
I suppose it is a gift. But you can turn this on by training in mindfulness and concentration exercises. The former increases lucidity. The latter increases clarity.

Frankly though, the dreams you get are the dreams you need to see and experience, whether you like the contents or not. If someone is not dreaming about code but about those other things, those are the deeper stuff related to life that the person needs to deal with.

If you are consistently dreaming about code, the gift is not that you are dreaming about code. The gift is that your daily life is aligned to a deeper sense of purpose and being. Your inner life and outer life is in better alignment than most people's. _That_ is rare.

I don't remember. So certainly was not properly documented.
Yes, all the time. I was a military academy cadet and I train all the time in my mind, I dream 12-24 times a year that I have managed to get back in and do basic/etc. I was a TA and I prep/teach lessons in my mind, and I also slice and dice code in my mind all the time.

I never know which I am going to get but coding is the most pleasant of them, by far. The higher my stress, the more likely it's not fun.

The fact that my current job is to untangle legacy Java code and we actively oppose any "unnecessary" changes hurts me, because I can't not untangle it in my head, working or sleeping. Resting/playing is OK though. That's why it's important.

Of course, we don't have any unit tests, because how else could we employ 2 testers per coder? And we obviously don't have any time for that useless stuff.