Hacker News new | past | comments | ask | show | jobs | submit login
How to Program in Your Sleep (bellmar.medium.com)
99 points by mbellotti on Aug 27, 2023 | hide | past | favorite | 50 comments



I can buy that information is consolidated for generalization during sleep. And also that the subconscious mind does a lot of work that we aren't aware of.

One aspect of this that hasn't been mentioned though is just fatigue. By analogy, if you were training in a gym for an hour and then decided to try to go for a heavy bench press, it might be harder and harder the more you try, since you are getting more tired.

But if you take a long lunch break or come back fresh the next day, it may be relatively easy.

So I think mental fatigue also plays into this. Although the other theories seem fairly established and more interesting.

But maybe you can extend the analogy further if you consider maxing out and then resting for a few days so that your muscles have made a slight adaptation (become slightly stronger). In this case, when you returned to the bench press, not only would your muscles be rested but also more capable.

This could be similar to the memory consolidation and organization that goes on during sleep which could provide an information schema that already incorporated key aspects of your problem and maybe previous similar problems/solutions, giving you a head start on solving it.

As an aside, it's interesting to think about how much work your memory is doing for problem solving with things like analogical reasoning. Which is one reason that it may be hard to measure intelligence accurately and fairly, since all skill and knowledge involves developing and accessing compressed problem/solution spaces.


I'll push back because, in my experience, this sensation arises in the still-very-tired aftermath of totally spending myself on a problem.

Solutions emerge in my head as I sleep, usually after a day of brute-forcing a problem so much that it spills over into my mind's eye during breaks, which spill over into my dreams, where glowing forms congeal into solutions.

I recently read some comments here about people having vivid dreams of playing Tetris. That's exactly how my dreams feel, but in mine, I see either code, foreign languages, or a spreadsheet. Extending your gym analogy, it's like hitting your PR the day after going all-out on volume training.


Pianists who slept longer can perform better than whose who waked up earlier to practice (source: some popsci book) i.e., perhaps sleep does more than just decreasing fatigue.


fatigue is a feeling that makes sleep, getting rid of it is not the purpose of sleep, it is to convince you to sleep


Along similar lines, there is Rich Hickey's talk "Hammock Driven Development":

https://www.youtube.com/watch?v=f84n5oFoZBc

Also Polya's How to Solve It, referenced in that talk:

https://en.wikipedia.org/wiki/How_to_Solve_It


I had an fairly extreme version of this. I went to bed one night after feeling defeated because I thought I'd made a fundamental design error and my core data structure was broken and it couldn't do what it needed to do.

I woke up in the morning with a solution in mind and went straight to the keyboard, but the strangest thing is I didn't really consciously know what I was writing, I just started typing as if straight from my subconscious. I was familiar with the code of course but I didn't think about the details of what I was writing. And it actually worked perfectly, basically first time.

It was a very spooky experience.


Oh, I do it all the times. So much, I know I don’t have to try too hard to solve a vexed problem. All what I need is to remember all the details and the difficulties arises from attempting solving it, so lucid that I can virtually juggle the things entirely in my head. Then I keep day dreaming about the problem and eventually go to sleep. Most likely when I wake up, I would have a solution, or at least a fresh new idea to try.

It also works during a toilette sitting :D That’s why for me an ideal bathroom should be well lit, preferred with sun light, well aired with lush green plants, clean and with material for reading.


>> a fresh new idea to try

Yes. The solution sometimes come as well, but the fresh new idea almost 100% of times after a power nap or something.


I get those programming dreams but have always really disliked them, and find I wake up feeling like I didn’t actually sleep, even if I was in fact asleep all night with code flying around in my brain like tetris blocks. I’m not sure I’ve ever woken up with a great idea after one of those nights.

I do find, however, that solutions to sticky problems pop into my head in the shower, during a long steady run, or after a walk in the park, which I guess is a similar phenomenon.


I got those with playing chess in my dreams. Always some difficult position that I need to find the best move in and when I finally do, the board size grows and somewhere "over there" is a bishop or a rook or so screwing up my whole previous plan, making me have to think all over again, but with a bigger board and an even more difficult situation.

Woke up from those somewhat with a headache, not well rested.


Agree. I’ve even tried “seeding” my last minutes of consciousness with other things so that I don’t dream about eng problems (hell, even dinosaurs?).

Feels highly dystopian that I’ve reduced my brain to an advanced calculator.


[Spoiler-free] Reducing the brain to an advanced calculator is a basic premise if Murakami's cyberpunk fantasy book Hard-Boiled Wonderland and the End of the World. One of my favorite books.


Walks have known to 'jog' the brain. Einstein did it all the time.


> wake up feeling like I didn’t actually sleep

I don't feel tired when I wake up, but I don't feel like I 'reset' either. I've had a couple of times where I'll wake right up and bang something out like I was being dictated to. It's almost like all the pieces were already there in your mind and they fall together when you aren't trying to force them. Brains are weird.


Vivid dreams usually happen during REM sleep, which is the deepest phase of sleep. So if you are dreaming, you are probably getting good rest, even if it doesn’t feel like it, e.g. because you woke up suddenly during a dream, rather than after it.


If you’re excessively lucid dreaming you get terrible sleep, anyone who has trained themselves to lucid dream will tell you that. There may well be a simple explanation but I’m on my phone so it’s annoying to look things up.


Is REM not the least deep sleep?


Yes, AFAIK the brain is electrically the most similar to being awake when it is in REM.

I’ve seen deep sleep used synonymously with “deep NREM” (non-REM).

They are indeed different, but both support cognitive function in different ways.


I found myself assaulted by the evil twin of incubation.

Half-waking in the middle of the night and realizing that programming problems from the office were thrashing around in my mnind like carps out of water.

Really, really irritating and ultimately fatiguing.


I have had a lot of issues with this for the last few years. I saw someone post on here a few days ago to tell yourself you’ll set a specific time in the future at which you’ll entertain those thoughts. For me, when I find myself thinking about specific work tasks, I just told myself “At 7:30am I will entertain this train of thought”, and did my best to think of literally anything else. I fully expected this to not work at all, but it was effective basically the first night I tried it. I fell right back asleep. The last two nights I’ve tried this have been quite restful. We’ll see how that continues.

A separate but related issue I’ve found is that I’m often dreaming in programming languages now, which is a totally surreal experience. I think this is like how some people say when you move to a new country and learn a new language, there comes a point where the language in your dreams shifts from your native one to your newly immersed language. But I find it happening to me now: a complete standard dream scenario, but all thoughts are expressed completely (and partially nonsensically) in SQL, or python, or classes and subclasses, interfaces, data models, APIs, tests, and error handling. It’s really odd. Especially because it’s not even specifically a work challenge, it’s just like a standard dream but my brains way of constructing it happens to turn it into a technical challenge somehow. These nights are rarely restful.

This probably indicates some underlying anxiety or something that I should more seriously and proactively address, but for now I’m just happy if I can get a restful 6-7 hours in.


Going for a walk often helps too. My campus had a nice place to walk and I'd often go for a spin and just relax and think a bit. If you're really stuck or totally off track go for a long one.

Don't use your phone, experiencing the walk is the point. Watch and walk and think.

The idle mind can be very fruitful, it's a shame that we've let attention machines steal this. Not that I'm any better.


If one remembers that the subconscious makes up approx 80% of the brain[0], there is a lot of problem solving potential in switching off the conscious and "backgrounding" problem solving to the subconscious.

Which in a way, the author is indirectly describing. Engaging in activities that are "automatic" (e.g. showering, long walks) also allows the conscious to drift and frees the subconscious to interrupt the conscious with some solutions. Hence the best ideas under the shower.

Taking a break from the problem can sometimes be the faster way to a solution, illogical for modern bosses who believe only working on the problem will solve it.

[0]=if you don't believe this then try to consciously pick up a cup of coffee and drink from it. The coordination of muscles, swallowing, and everything besides is the subconscious. The conscious, if at all, had the thought "I want to drink coffee" or it might just have been a feeling between messaging and eating a breakfast toast!


in my own experience i feel like my subconscious mind does most of the problem solving and my conscious mind is mostly used for identifying the problem, selecting the input data, and then observing the result. if you flip your perspective you might also consider that while you are using your brain to program a computer you are also using the computer as a tool to program your brain. what makes computers so unique is that they give you the ability to control the input to the audio/visual centers of your brain so that you are able to manipulate the stream of information that is passing through your (very limited) short term memory. typing plays an interesting role here as well because there is subconscious muscle memory and so once you practice enough you write code the same way a musician plays a piano which is subconscious reaction between visual symbols and muscle memory. whats different with computers is that instead of reading from a printed music sheet you are able to control the sequence of visual symbols that trigger the subconscious muscle memory reactions that result in typing.

if the brain is actually a biological neural network then this is not surprising. input takes time to propagate through the layers of the network and sleep is a necessary part of how that biological process works so the information needed to solve a problem might take a nights sleep to propagate to the depth where it can be solved or it might need a variety of other inputs that take time to acquire before enough information is ingested to reach a solution.


> Taking a break from the problem can sometimes be the faster way to a solution, illogical for modern bosses who believe only working on the problem will solve it.

Yep this is the most important part. If you go on a walk or shower but think about how to solve the problem you're not going to get this benefit.

Sleeping is ideal because you have no opportunity to consciously think about it but it can be done while awake if you find yourself truly disengaged from thinking about your problem.


What a clickbait. Calling this "how to program in your sleep"? I mean, seriously? Everyone with sufficient experience knows that putting aside a problem that you're trying to solve and giving it another go some time after can be of tremendous help. What it would be nice to know or at least have some explanation is why this works most of the times.


"Why We Sleep" by Matthew Walker covers how and why this works.


So many interesting articles I'm never going to read because of the paywall. I'm curious how people who see this actually create an account to gain access?

I personally don't think it's worth giving up an email address and spending the time to do so to read a blog post.



What I usually do, is I have what I call a “public” email. This is a gmail account I use to log in in any paywall website or any service that requires an account to just see some content and I don’t care who has that email, as I just ignore any email that arrived to that account.


Shout out to Anonaddy, sorry addy.io


just add an archive.is/ in front of the url


Use an archiving service like archive.ph

The article isn't too much longer past the paywall and basically just says "don't try to, just familiarize yourself with the relevant code to a specific problem and you might wake up with the answer"

"How to program in your sleep" is a click baity and inaccurate title for the content.

A better one might be "on programming in your sleep"


scribe.rip also works for medium. Or you can host your own instance.


This one appears to be a member-only story, but Medium shows a paywall ad on non-member stories too. It's a bad business making money of articles that they don't own.


I remembered it happen in a very strange way when I studied calculus. I had a hard time to remember the integration rules and how to apply them. Spent a lot of time on it. But at one point I had a dream where integrals came "flying in" like in a computer game, and I solved them one after another, just like I can solve 1+1 without hesitation. Whether I really solved them or this was just imagined is of course the core question. But the dream was so detailed and crisp, and I felt so conscious in it, that I think I may actually have done that. It was a feeling I very rarely have felt ever before.


Question is, were they easier after you woke up?


I don't remember exactly, this is more than 25 years ago, but I think in the dream they were easier than they ever were when awake. In the dream I was some kind of calculus-ninja. I know this sounds ridiculus but personally I believe that I actually were in a state of mind were I mastered the topic I had studied.


I expected something more insightful. As someone who don't have sleeping problems, but have family members who does, from what I seen the most effective impact happened when:

- You are going to bed only when you're tired, don't try to go to bed and hope you will become tired by just laying.

- Have at least one long walk a day (it helps my sister when she is doing it when it's still daylight, but ofcourse it depends on where you live)

- Don't drink coffee after 14:00

- Stay off social media after dinner time

- If you are reading a book using a screenreader or laptop make sure you filter the bluelight


I've been led to believe that the reason why a lot of written exams include the instruction "read all questions before starting on the problems" is due to this subconscious "cooking on the back-burner" effect. Problem solving in your sleep might be related to that strategy. I haven't read any empirical studies on the effectiveness of this testing strategy - but I suppose it should be fairly easy to set up such an experiment.


The reason that I have done that is so I know how long to spend on each question. If the last questions look extremely difficult then I know to spend more time on them, or I might even attempt those before the easier ones.


Many years ago I played drums in a band, and often the guitar players would write weird little off time parts that I couldn't do at first, but I could the next day. I used to tell them that I would practice in my sleep. The first time I said it I was ridiculed, but when I nailed the part it became a running joke that I should bring a bed to the practice space.


I never knew the term “incubation” existed for it. Good to know!

I’ve found for me it’s most effective when I very specifically lay out the rules of the problem in text, go to sleep and re-read through the rules. Usually I’ll have some new idea and change the rules I made to fit this probably-better idea.

Sometimes it’s pretty interesting to see how the “specs” of the problem change before and after solution.


Incubator: make money in your sleep.

Incubation: solve problems for money makers in your sleep.


I was introduced to this concept as a kid by "The Great Brain" book series. Was surprised to discover as an adult that it actually works in many ways. I'm a huge proponent of sleeping when I'm stuck on something. The tricky part is recognizing when I'm in an unfruitful debugging session and pulling myself away.


Cormac McCarthy wrote an interesting, somewhat speculative essay about this idea in 2017: https://nautil.us/the-kekul-problem-236574/



This is the diffuse part of learning and I thought it was general knowledge by now? https://www.coursera.org/learn/learning-how-to-learn


[flagged]


> please don't post complaints about paywalls. Those are off topic.

https://news.ycombinator.com/newsfaq.html


They're probably hoping for a reaction like "Oh man, I gotta know the rest, let me pull out my credit card", but my reaction is just "Seriously? I wasn't giving you my money before, and I definitely won't now."

(On closer inspection, you're only "paying" by creating a "free" account with them -- but paywalls look like paywalls no matter what the price is...)


That can put archive.is out of business.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: