Programming is Like a Dream

Have you ever noticed that computer programmers are very easy to startle? Walk up behind an accountant or a web designer sketching out banner ads, and nine times out of ten they’ll know you’re coming from a mile away. But computer programmers aren’t like that. You can stand right behind a programmer for ten minutes and quite often they will not even know you are there–especially when they are working on a difficult section. The larger the system, the deeper the trance.

I just read two fantastic essays describing programming as a dream-like state. I’d never thought of it this way before, but I’d have to say that’s the most dead-on accurate description I’ve ever heard.

Now, imagine you were in deep sleep, dreaming away about apples at 3am, and I came bashing into your room and said “Sorry, but we need you to dream about bananas now.” Do you think you could go straight back to sleep in a few seconds, dream about bananas for a bit, and then jump back to your original dream about apples? No, of course not, but this is what managers expect when they throw new tasks at us while we’re busy coding the first one. When this happens we’ve lost the hours we’ve spent on the first dream, we’re completely lost for half an hour, and then we eventually manage to get into the new dream.

This is very true. It takes a little while to “shift gears”. For small programs, it’s not so bad, because you can conceptualize the whole thing in a few minutes or seconds. For large systems it takes longer to get yourself back into the right frame of mind. You have to think about all the things you were thinking about when you put it down last, and this is often a lot harder than it sounds. There’s a small time penalty that’s paid every time a programmer sits down to work, but it’s only paid once per session. This is why a lot of programmers prefer to work in one long stretch instead of several short ones. In six 30 minute stretches, zero code will get written–zero good code, anyway–because you spend the entire time just getting started. In one three hour stretch, however, you might just compose a masterpiece.

I can sit down and start coding right away, but I don’t really “hit my groove” for an hour or two. Sometimes I try to accelerate that by leaving myself a thread the day before. I’ll intentionally not finish a block of code I was working on, but I’ll leave myself copious notes on how to write it so that when I sit down in the morning I can start right away on that block. In the morning I don’t really have to think about the block too much because the answer is right there, but by-and-by as I code it up the thoughts start rushing back to me. By the time I’ve finished writing the block, my head is where it needs to be and I can pick it up from there. Sometimes if the code is very complex I just keep thinking about the code until morning. Most programmers can and will do this, too. Some perhaps can’t hold onto the code for days or weeks, but virtually all can for a few minutes or even a couple of hours.

I know it sounds strange, but think of it this way: Have you ever had a dream that lingered? You know, when you have a nightmare or other intense dream, and it keeps coming back to you while your doing other things throughout the day? Your mind is still dreaming the dream even though you are awake, and you can feel it back there drifting around. Keeping code in your head feels very much the same way.

There’s a right and a wrong way to interrupt a programmer. The best answer is “don’t”. But if you must… If you think about programming like dreaming, you’ll realize that programmers remember more if you interrupt them gently than if you barrage them. If someone wakes you out of bed and starts shouting a long list of things at you to remember, you’ll almost certainly forget what you were dreaming. However, if someone shakes you gently and gives you a few seconds to open your eyes and look around before they start talking, it’s a lot easier to remember the dream for later. The same works for programmers. If you just walk into their office and start talking, one of two things will happen: they’ll completely forget what they were coding, or they won’t really be paying attention to you. However, if you quietly walk up to them and let them know you are there but say nothing until they are ready, the programmer can come to the end of the thought they are on. Once they’ve finished their thought, it will be easier for them to pick up next time and still pay attention to what you have to say.

Let’s take a maze for example. There is a task for the programmer to come up with an algorithm of finding the way out of the maze. When a programmer is working on this task he isn’t just a God’s Finger showing the directions to a little girl lost in a great maze. He isn’t that girl or the walls of a labyrinth either. He is actually all of that in a same time. In order to solve the task he must BECOME the labyrinth, the walls, the lost little girl and whatever else may just came along with it. It is not a figure of the speech – the programmer is literally SLEEPING and DREAMING that all in his mind.

My brother contends that it is this same phenomena that makes programmers so bad at estimates. The problem is, as he says, that the programmer already knows everything that needs to be written. When you have it all in your mind, it seems like it should be easy to write it all down. But it’s not. The physical act of writing the code takes a long time. But more importantly, your mind never thinks about all the “meaningless” details. It knows how to code them so well it doesn’t even need consider their existence anymore. Unfortunately, the computer still needs them. It can’t infer. All those loose ends, niggling details and corner cases end up eating a great deal of time… sometimes more than the rest of the program.

How does programming feel to you? What is your experience like?

Share and Enjoy

53 Responses to “Programming is Like a Dream”

  1. Vaughn Says:

    Good insight about estimating. People always expect an exact estimate from me and the best I can do is a range, say 1-3 weeks or something similar. Sadly I don’t get into the flow as much as I used to, far too many new responsibilities. I may as well be a manager, but I’m expected to code as well, and the two just don’t mix.

    I miss the days of working on new and novel ideas, but when you have to make money you drift towards the lucrative area of our industry: dull, complicated business software no one wants to write.

  2. Lisa Says:

    Yeah, I manage too, and I agree the two don’t mix.

    The best approach I’ve found is to try and block off parts of the day for each, and just shut my door or put on my headphones when I really need to jam. (Sometimes I don’t even turn any music on! I just listen to white noise or nothing at all.) Thankfully everyone here is pretty good about not bugging programmers with headphones on unless they really need to.

  3. Mr Soft Says:

    Excellent article. Accurate and useful. Thanks

  4. Programming in your dreams « The ByteBaker Says:

    [...] Programming is like a dream [...]

  5. John Says:

    I remember in college that I used to write out the code on paper before I went over and typed it into the computer over at the computer lab. If I recall correctly, it worked perfectly every time. Mind you, these weren’t hugely involved projects. But as a comparison, for the times I just deep-sleeped it, typed ‘er out in the trance state, my programs were fraught with errors. For me, at least, putting pencil to paper interrupted my world-class dream state where I could plunge into unwieldly complexities that were only tangential to the solution.

    As a self-anointed world class dreamer, I’ve got to discipline myself, or I’m fraternized.

  6. Pierre Says:

    I have been programming for years with the sound of breaking beach waves through headphones. Put them on, start the sound, and off you dream ;-) Having the complexity of a large project or complex challenge in your head, with relaxing sounds in your ears is a cool creative kick. Nice article.

  7. Scott Says:

    This is dead accurate. I call it a “programming fugue”. My family’s had to learn that you just don’t interrupt Dad when he’s programming. Over time, I’ve found that, if the person interrupting just stands there, I’m able to sort of “partition” my awareness so that most of me’s programming, but a little part’s aware that somebody wants something, and I can be very intentional about getting to the point where stopping isn’t too costly.

  8. Rodney Keeling Says:

    Excellent article! I love it!

  9. Dan Says:

    It’s called “flow” and it’s hardly limited to programming. Any activity requiring intense concentration and the fluid use of experience and skill will generate it. You think a surgeon wouldn’t be easy to startle during an operation?

  10. Desi Says:

    I totally agree!!
    If I am writing some code and I get interrupted, I completely lose my place, my “trance” never really comes back, and everything I had in my brain is like, gone.
    and people wonder why I get so irritable when I am interrupted!

  11. The Meaghers · Irritability and Working Says:

    [...] http://www.independentdeveloper.com/archive/2009/03/17/programming-is-like-a-dream [...]

  12. Anonymous Says:

    Love the article. I am a senior in high school, and I actually noticed this today when working on a huge lab. I know that this is very little compared to what you guys do, but I still feel the same way. Anyways, I am very passionate about computer science (competitions, comp sci club and stuff), and am seriously considering majoring in it. Can anyone here tell me what a career in comp sci is like? From what you guys have said, it sounds like my ideal job.

  13. Izkata Says:

    Psychologists call it “flow”, everyone else calls it “the zone”. Especially gamers. It’s the exact same thing, though

  14. Paulius Maruška Says:

    This is so true… I think I’ll print a few copies of this and throw around in the office… :)

  15. RH70 Says:

    Wow! What a great read, that’s exactly how I feel when I program.

    Unfortunately where I work most people are aware they shouldn’t interrupt, but do it anyway and think it’ll be okay as long as they precede their interruption with a “…sorry, but … ” or a “…I know I should put this on the helpdesk, but….”

    I should send this round to them all! :-)

  16. Rbuenon Says:

    I think programming is more like a nightmare, you never have time for yourself, you spend a lot of time on things you tend to give for granted, weekends gone, late night working and the worst part is having to try to stay up to date on technologies and stuff. Every day I regret more not working on something else than programming, worst part is I used to love it

  17. Jamie Says:

    Rbuenon: sounds like you need a new job. I work from 8-4 five days a week. No overtime, no weekends – ever. And it’s not really too hard to stay up to date with the latest tech… maybe 15-20 minutes every day over coffee.

  18. Bryan Says:

    Personally, I always tell my kids that programming is an invaluable skill, but to avoid taking it as a career. Aside from the crazy demands most employers make, if you try to forge your own path there are always the fear of someone showing up on your door with a patent on the idea of using a program to operate a computer!

  19. Berni Says:

    Nice and true article, I like the dream metaphor. A person that has never programmed in his/her life has now idea how complex and demanding it in general really is. The article brings a good insight on this.

  20. Tyler Says:

    That is spot-on. I never noticed that about myself before.

  21. Eric Says:

    Truly a work of art – you’ve nailed it right on the head. Thank you for this!

  22. Kathy Says:

    Very useful info. My hubby is a programmer and I can be in the same room with him working on code and scare 5 years of life out of him by just asking a question. It doesn’t occur to me that the podcast and music he’s listening to is any different than the sound of my voice, but when I say something… it’s like a jolt directly into his brain stem. I have to send him an instant message and say, “hey, I need to ask you something when you have a second.” Mind you, I’m only 4 feet away at the desk across from him. It seems ludacris to me, but hey, if it works, what the heck.

  23. Jason Sheedy Says:

    It’s very true. I used to be such a fun loving, easy going guy before I took up a career in software engineering. I work in a busy radio station and have constant noise around me, but after many years I’ve developed coping mechanisms that help keep the gremlins at bay.

    1. Some good music.
    2. Some good design work and a clear road map for the project/task.
    3. Leaving a bread crumb tail. i.e. code comments, good project management tools, etc
    4. Evil facial expressions and growling sounds.
    5. If all else fails, threats of physical harm …..

    On topic here’s a little video I posted a few days ago.

    http://www.youtube.com/watch?v=4ddkTYpCcc0

  24. Dirk Says:

    never saw programming this way… but this article is so true!
    great work!

  25. John Willemse Says:

    I would prefer “trance” over “dream”, but it comes down to the same effect. This is the main reason I sometimes get in a fight with my girlfriend. She never learns not to talk to me when I’m coding, because I won’t hear her any way…

  26. FireBath Says:

    After a while people close to you learn to deal with it, my mom would come and put food on my desk … take the food the next morning untouched and she would place another plate and so on. I talked to her about this she said that her soul hurt because i wouldn’t eat but she knew it was better not to interrupt me. After a while i learned to eat not thinking about it because i started getting sick. People at work now are not used to this and it is very distracting. It’s also very hard to explain to them what you mean by “do not disturb… ever” i’ll show them this article next time.

  27. jason Says:

    Love the description – so spot on.
    I would add however that sometimes when a problem seems to difficult to resolve or if you have been working on a problem so much that you are too involved in it going round in circles trying to resolve it – you sometimes can not see the wood for the trees, and sleeping on it overnight will add a sense of clarity to the whole problem and either a new idea comes to mind as a better way to code it, or you wonder how and why you were going about things so convoluted when it was really quite easy. I find now that if a problem seems to trouble me, I will put it to bed for the rest of the day, but still have it in the back of my mind and sleep on it – the following day 9 times out of 10, it will be resolved in a better more effecient method that i have come up with. JB

  28. The Top 10 Things Project Morons Say | The Virtual Experts Says:

    [...] further reading: http://www.independentdeveloper.com/archive/2009/03/17/programming-is-like-a-dream http://alexthunder.livejournal.com/309815.html [...]

  29. Roozbeh Says:

    on the point. thanks

  30. Ronny Says:

    Good article. I am struggling with the same issues. Interference is not good for me. I getting out of a state of flow or I am not getting in to it. Interference can be so much. Unfortunately I do not have my own office. We are 5-6 persons sitting in the same small room all the time. Two colleagues conversation, or one colleague talking to me, mails poping up, instant messages, my phone, what ever will take me out of my state of flow.

    Neal Ford the author of The Productive Programmer handles this in his book and talks about this. I have the book and have attended to his talk. He recommend using headphones with or without music, what suites you best. This will probably tell the human interferers that you are occupied. Or pretend you are on the phone :-) In the chapter Focus he recommends turning off all things that distracts you, balloon tips, growl, instant messenger, mail, and such. Also create quiet time. I.e. 9-11 AM, 3-5 PM.

    For me all context switching between tasks and systems/projects with an manager or other consecuenses forcing me to re prioritate is something of the worst.

    Anyway good luck with finding the state of flow (and keeping it for some time)

  31. Joost Says:

    Great post! The right music gets me in “the flow” when my workday starts. Stopping at the end of the workday is a lot harder for me, since the feeling of being productive (like a trance) is so good. The part about writing notes under a part that isn’t finished is a great idea!

  32. Tony Weeg Says:

    thank you very much for this post… it is spot on!

  33. Martins Blogg » Mitt jobb är en dröm Says:

    [...] enligt den här artikeln Filed under Datanörd var uri = [...]

  34. Chilano Says:

    I’ve never really thought about programming in this way, but I think you’re spot on with regards to work flow. If I keep getting interrupted when I’m working on something complex productivity takes a big hit, but if I can keep working on the task for long periods at a time productivity improves. The downside is I then often lose track of time, but I guess you can’t have everything :)

  35. rdsouza Says:

    Until now I though I was abnormal. And was losing my mind.

    The knowing the symptoms are common amongst other programmers bring GREAT RELIEF.

    GREAT ARTICLE!!!

  36. Charlie Rubin Says:

    This is similar to meditation. You can sit and try to still your mind, but it’s only after 20 minutes that you really are even beginning to get focused. If you can keep at for an hour or two, you can go really deep. You can’t go really deep in 5 minutes – the mind takes time to focus. Same with programming an intricate project. Maybe that’s why so many of us get our best work done late at night when there are no distractions.

  37. kestrel Says:

    Hack mode… on. I find my best time to go into my programming trance usually hits around 10-11 PM, and continues on to around 3… after that, things start getting a little too fuzzy. Putting on some good ambient (Oddly enough, the Halo 2 Soundtrack Volume 2 works great for this) really helps me get focused.

  38. Yamill Says:

    [...] came across this interesting article by the Independent Developer Blog. I woke up this morning like other mornings I’ve had when my mind is in “Programming [...]

  39. Melissa A. Says:

    I refer people to this ALL the time. So glad I came across this article! <3

  40. Prakash Says:

    Interesting article! I too found this comparision very correct… My mom used to come behind me while i was programming all the time and i just used to say yes to each of her questions. :)
    enjoy coding!

  41. Programming is Like a Dream – … @ ermisa Says:

    [...] is Like a Dream – http://www.independentdeveloper.com/archive/2009/03/17/programming-is-like-a-dream [...]

  42. Programming is like a Dream… by Lisa « SQL Server Programming, Tips & Tricks Says:

    [...] stumbled into Lisa’s post which talks about Programming as a Dream. I liked this article very much and the illustration given [...]

  43. jocuri cu bile Says:

    Hi, how are you? I hope you do well. I wanted to say that I like Independent Developer » Blog Archive » Programming is Like a Dream.

  44. Am I Dreaming? « Status Not Quo Says:

    [...] So sometimes I have a really hard time coming up with something to post here on the SNQ blog… well OK I always have a hard time with it but sometimes it is really hard. This seems to be one of those times…  So what I want to do is share with you something that I came across a while ago that I found very interesting and hopefully you will too.  Hopefully it will also give you a little insight into the mind of a programmer: http://www.independentdeveloper.com/archive/2009/03/17/programming-is-like-a-dream [...]

  45. scalino Says:

    Great article dude!

    very very interesting point of view, will definitely experiment on this, thanks!

    Scalino – NHA webmaster

  46. Jible Says:

    It’s called “flow” and it’s hardly limited to programming. Any activity requiring intense concentration and the fluid use of experience and skill will generate it. You think a surgeon wouldn’t be easy to startle during an operation?

  47. scarfacedeb Says:

    this’s exactly why I’m so struggling with estimating time for the projects. great insight! never thought about it that way.

  48. Bob K Says:

    My wife is an artist and she is much the same.

  49. infogulch Says:

    I like to think of it as a stack machine. If you gently let me know you need something I have a bit of time to finish my current operation and push my critical registers onto the stack before jumping to your subject (with hot-swapping obviously), but if you just interrupt me and start overwriting my registers I lose a bunch of work, not to mention being confused as to what’s going on in the first place.

    Of course that analogy doesn’t work very well with non-programmers. In that case this article is excellent.

  50. Mentifex (Arthur T. Murray) Says:

    I keep writing the same artificial intelligence (AI) program over and over, in [English] and in [German] and in [Russian]. It is so difficult to code the AI Minds in Forth or in JavaScript, that I need to enter one of the dream-like states described above. Generally I can only code AI in the middle of the night or the early pre-morning. If some morning work needs finishing up, then I might manage to work on it some more in the afternoon or evening.

  51. Links & reads for 2013 Week 16 | Martin's Weekly Curations Says:

    [...] Programming is Like a Dream [...]

  52. Ronnie Says:

    Very interesting.

    I’m a programmer also. I may though enlarge this not only to programming activity, but to any task requiring a high amount of concentration.
    I can imagine designers, surgeons, people in meditation state, etc etc

    If I sound wrong please let me know :)

    R

  53. Daniel N Says:

    I found this article so relatable! I love this so much because i think this same thing, but (as you said at the end) I can’t really put it into words good!
    Thank you for saying it for me!

Leave a Reply