Take the 2-minute tour ×

I have heard about programmers coding for two days without sleep and drinking coffee and Red Bull. Also in movies like The Social Network, in a scene they show that Mark Zuckerberg has been programming for 36 hours. Also i read somewhere that in companies like Facebook, Google, foursquare, etc. they can code for more than 24 hours without sleep.

Is this really true? Can you actually produce high-quality code if you are sleep deprived? Can things like Red Bull make up for sleep?

share|improve this question

closed as not constructive by MichaelT, Robert Harvey, Dynamic, gnat, Kilian Foth May 27 '13 at 7:33


Holy Crap! I don't think the are humans/programmers. May be aliens? :) –  Tech Jerk Jul 30 '11 at 5:27
"The Social Network" is not a documentary. It is only loosely based on the actual events relating to the founding of Facebook. As a marketing ploy the "true story" aspect was played up, but whenever the author and the director were cornered by an interviewer they would admit that it was mostly their imagination about "what could have been". –  Charles E. Grant Jul 30 '11 at 6:00
Perhaps this should be moved to skeptics.stackexchange.com... –  Evan Jul 30 '11 at 10:49
Some can but that is because they normally produce above-high-quality code. Unfortunately it is much more common to produce average quality code even when fully rested... –  user1249 Jul 30 '11 at 15:16
I read this question the day after having been awake for 38 hours, 32 of them at work. I wanted to say something about it, but basically any non-distracted time spent programming is good for your output, but when you're totally tired you're not non-distracted. You can however build, test, debug, document and polish if you're obsessed with getting it to some imagined correct state. –  dlamblin Aug 1 '11 at 21:16

17 Answers 17

Simply No. Coding for 36 hours has nothing to do with programming, rather it's an attribute of human. Very few people can stay awake for 24 hours and even when they stay awake, their mind really loses problem-solving skills. Drivers who are sleepy, simply hit other cars. Accountants who are sleepy, simply make mistakes in their calculations. Also many programmers when sleepy, write less quality code.

PS: There is an illness called insomnia that makes you sleep less. But I don't think Google hires people with such illness. :)

share|improve this answer
+1: Really good programmers spend most of their time thinking about a problem before they touch a compiler. When they do the solution is generally well thought out, simple, abstract, and easily maintained, coding then becomes trivial. –  Justin Shield Jul 30 '11 at 6:07
@EOL :D true enough, that should read "keyboard" –  Justin Shield Jul 30 '11 at 8:19
My own experience is that by about 9pm, after a 9am start (so 12 hours), I'm tired, irritable, can't think straight, and am incapable of writing anything or debugging. Home and sleep is FAR more effective than silly things like pulling all-nighters. That this is done, let alone effective, is a myth. –  quickly_now Jul 30 '11 at 8:45
@quickly_now Exactly. The code gets worse and worse exponentially in a function of time. So, technically, you could code as long as you're able to sit in front of a computer. But then, don't come to SO and ask how your O(n^n) sorting function can be optimized ;). –  Dr McKay Jul 30 '11 at 9:16
Wait, you're allowed to sleep after just 24 hours of coding? I knew this job sounded fishy when I started! –  Nick Craver Jul 30 '11 at 10:38

It's probably one of those well-known, persistent myths. You hear about it a lot because it's a compelling idea, but it has no real basis in fact.

Oh, sure, maybe some young kid fresh out of high school can pull off what appears to be some sort of coding miracle in 36 hours. But is code written in that fashion maintainable? Is it even readable? Does it scale? Does it follow sensible programming practices? Is it documented?

Twitter hacked together a site that worked, and then wound up rewriting it the "correct" way, because it fell down when the load got too large. Facebook put together their original site in a comparatively short period of time for such a project, but later brought in a bunch of new developers to rewrite the PHP platform that the website was running on, because it wouldn't scale.

The exceptions prove the rule.

share|improve this answer
One might also view these as compelling reasons not to worry about doing it right the first time - at least, not when you're potentially creating a brand new market. –  Aaronaught Jul 30 '11 at 19:15
It may not lead to high-quality code, but if you have your basics down and can do TDD "in your sleep", then the code won't be that bad. The big thing that coding while tired does it that your brain is less likely to ignore random thoughts and so you get more creative. en.wikipedia.org/wiki/Sleep_and_creativity –  Ape-inago Mar 13 '13 at 19:53

The only part that could be true about this myth is that programmers do perform best when they are uninterrupted for an extended period of time. As you are coding, the more things you can juggle in your head, the faster you can code because you don't need to look up things like API usages, or how a different part of the code was written by you or someone else. I find that when I get interrupted, it always takes some measurable amount of time to get back up to full speed, and if I'm doing something important (or fun), sometimes I will forgo going home at normal time because after hours is when your interruptions go home. I've also been known for staying up till 3 or 5 in the morning for the same reason.

However, like I said, your speed and quality of your code depends on how much attention you are paying and how many things you can juggle in memory. When sleep becomes an issues you may think you are working at your full capacity but you really aren't. Most software developed as in the examples you provided, gets off the ground fast but just as fasts it ends up being huge liability and maintenance headache.

You can definitely produce lots of code if you work a lot, and with enough effort you can crank out feature after feature. But without paying attention to architecture/design you will not produce easily scalable, maintainable or extendable software. Speaking from experience, it is MUCH harder to think about design and juggle components/interfaces/abstraction layers in your head (or on paper) than it is to keep writing pure code.

share|improve this answer
+1 for adding the idea that uninterrupted time can be quality time (but only in reasonable doses). –  EOL Jul 30 '11 at 7:57
@DXM concentration helps a lot. Quality of time over Quantity of time –  lovesh Jul 30 '11 at 8:45
@lovesh - I wouldn't say exactly that. (quality of time) x (quantity of time) = results. Increasing either one increases results. However increase in time, eventually decreases quality. Our goal is always to maximize results. –  DXM Jul 30 '11 at 20:14

The whole thing just sounds like an exaggeration of being "in the zone." When you're entirely focused, as a coder, time is warped, minutes become seconds, etc. You're probably at your most productive. It's sometimes difficult to get in that state, and quite easy to get out of (external factors mostly), but when you are.... wow!

share|improve this answer
I was writing my post thinking about how to include the phrase "in the zone" when you posted this. –  knb Jul 30 '11 at 13:04
Indeed if you are in the zone it is a lot easier to code very long. However losing focus once you've coded this long is unpleasant to say the least. –  DasIch Jul 30 '11 at 14:48

I can - and did at times - program for 36h straight.
I think the worst thing I ever went through was a week with about 10 hours of sleep or so.
For me, caffeine and energy drinks did not help. In fact, on such a long term, caffeine can have rather negative effects. My advice is to drink a lot. Keeps you hydrated and the walks to the toilet are a nice side effect: You stretch your legs a bit and you automatically make short breaks.

That being said, I find this increasingly hard. I would suppose it is a capacity, that is drained and eventually exhausted. And maybe has some negative health effects - physical or mental, long or short term, I can't tell.
What I can tell is that you feel like a zombie and you will continue to feel like that the days after such a marathon. Personally, I had a really big burnout after doing this frequently for about a year.
That is to say: Some people can work efficiently for such a time span, but it comes at a cost.
It was usually the consequence of poor planning and having had no experience in filling the gaps left by non-technical project leads, it was the only option.

Now you will rarely find quality code being produced during such marathons. However the main cause of this are the circumstances, in which those marathons occur: Situations, where you need to deliver features X, Y and Z within a very short time frame. Nobody really cares for code quality at that point, which is why you amass a lot of technical debt through quickfixes and other hacks.
At the same time this indicates the intact performance of the brain: Quickfixes and hacks require both overview and creativity.

You should not forget, that quality code is rarely written in a single run. Especially if the code has a long life span. Code quality is achieved through review and refactoring. Nobody will bother doing that 48h before a deadline.

The bottom line is: You should only work as long as you can and not longer. If you can work only for 4h, then ok. Take a break and work thereafter. Trying to stay awake for 36 hours within which you get 8h of work done is pointless. You get twice the work done if you make 4 sessions of 4h each and use the remaining 20h to regenerate.
If you can work such long hours, it means you are more flexible in responding to underestimation. However the long term solution is improving your planning and estimation process. If that is impossible at your work place, switch jobs. If people expect you to work such long hours, switch jobs. You don't have to prove anything to anyone.

share|improve this answer

Good programmers can indeed program for 36 hours. It doesn't mean they can produce their best quality code for 36 hours. I'm not a good programmer, and I did it several times in college, and even a couple of times in my 30s when trying to fix bugs for ship deadlines. It's generally a stupid idea and reflects poor planning and scheduling skills.

share|improve this answer
And just because you can does not mean that you are effective, especially after about the 12 to 15 hour mark. –  quickly_now Jul 30 '11 at 8:44
Bad programmers can also program for 36 hours. The length of coding time has nothing to do with the quality of the coder. –  Marjan Venema Jul 30 '11 at 10:20

You can stay awake and work for 36 hours if you are healthy. But in this time you will not write your best code or solve very complicated problems. I have worked for very long hours once in a while. Most of the time this was to keep some deadlines. But work then was mostly adding minor features like printing some lists, polishing some layouts. Nothing where you need much thinking, more like a lot of typing. The main features and complicated parts of the programs where already finished.

Sometimes your lack of concentration is the main reason for the long hours. We once had a deadline the next day. After an already very long day we had finished the whole thing and it was 2 am. There was only one nasty bug left. My boss had an appointment with the customer at 9 am, so there was plenty of time. It took me several hours to find and fix something that otherwise I would have fixed in half an hour. I just knew for sure that I would be able to find it anyway and there was no reason to let my boss down, since somehow the night was gone anyway.

share|improve this answer

Yes. Plenty of anecdotal information indicates it can. I doubt anyone can physically make a habit out of work marathons. Medical interns pull these types of hours.

Are you likely to make more mistakes, probably. I guess this all assumes you can write quality code in the first place. In these situations, you're under the gun and just want to get it to work. Quality isn't a consideration. We'll fix it after we get funding.

share|improve this answer
+1 for the reference to medical staff. I think overworked hospital doctors are doing this routinely... working stressful night shifts followed by dayshifts... sure way to be burned out after a few months or even years. –  knb Jul 30 '11 at 13:32
Now there is a comforting thought ;) Sleep deprived interns and people with life threatening health conditions. Try fixing those mistakes "later". –  Leigh Jul 30 '11 at 17:18
The risks posed by sleep deprived interns is well recognized, and many organizations are eliminating the practice. In part it holds on because the doctors who are doing the training put in those long shifts. –  BillThor Jul 31 '11 at 19:12

It is not impossible and it has happened in real. Since the chapter is long, let me quote the actual paragraph:

Members of the tight-knit group called themselves " hackers." Over time, they extended the "hacker" description to Stallman as well. In the process of doing so, they inculcated Stallman in the ethical traditions of the "hacker ethic ." To be a hacker meant more than just writing programs, Stallman learned. It meant writing the best possible programs. It meant sitting at a terminal for 36 hours straight if that's what it took to write the best possible programs. Most importantly, it meant having access to the best possible machines and the most useful information at all times. Hackers spoke openly about changing the world through software, and Stallman learned the instinctual hacker disdain for any obstacle that prevented a hacker from fulfilling this noble cause. Chief among these obstacles were poor software, academic bureaucracy, and selfish behavior.

Of course this doesn't mean that this is a one rule for all. Some people can do it, while others cannot. The most important thing is not to get interrupted, and to work during the periods that you feel very productive. Thus, you can try for yourself and make the conclusions :)

share|improve this answer

I guess it's possible, if you're a machine -- I'm not doubting that some can do it. But experience has taught me that the vast majority of programmers will write worse code shortly after the 8 to 10 hour mark, and horrible code after the 16 hour mark.

The few times our team was forced to pull an all-nighter, we actually ended up with some code that needed to be rolled back.

share|improve this answer
... based on my recent experiences with Facebook, I would say that it's pretty consistent with my argument. I got about 3 or 4 errors using different parts of Facebook today. –  Kaleb Brasee Jul 30 '11 at 5:27
@lovesh "It's said that they do it" and "they do it" are two different things. –  Scott Wilson Jul 30 '11 at 9:58

I doubt it to be honest. In fact despite myths and stories about people achieving X, Y and Z having been awake for 24 hours, they happen to be in extreme circumstances and are rare.

Way back in the day, I used to provide typing pool for a lawfirm who occasionally had people pulling all nighters to try and get stuff out for particular times. Anyone who did crazy hours drafting documents generally wound up sending those documents down to have their overnight changes reversed. In my view, it's not possible to consistently perform at a high level for more than about 12 hours at a time (and even that's excessive) surviving a lack of sleep by increasing your caffeine levels. I think it's a story people like to tell, but if they are honest, they will admit that their average work over longhaul sessions, regardless of what the job is, be it coding or writing legal documents, is rarely, if ever, good enough to match their output if they got adequate rest.

There's nothing special about coders no matter how good they are, like drivers, like operators of heavy machinery, they are subject to fatigue and I'd be stunned if anyone could prove a coder could provide high quality output without a rest within about 12 hours.

share|improve this answer

When I was studying programming at university there were a few nights where I felt more productive than during the day. It has to do with the fact that there are less distractions at night, the weed has made me comfortable enough to sit still and I didnt actually get up that day til 2pm anyway so I wasnt too tired. I could code through to 8am before I was insanely hungry for my breakfast. With that said the next day I would mentally crash by 5pm and there was no way I was being productive. Programming at night can be more productive but making yourself sleep deprived doesnt ever increase code quality and you wouldn't ever plan to be tired when coding.

share|improve this answer

I and many other creative people demonstrate features of bipolar personality. When designing software, I tend to follow Feynman's algorithm:

  1. Write down the problem. (Minutes)

  2. Think real hard. (Between days and years)

  3. Write down the solution. (Days)

A hypomanic episode with drastically reduced sleep (caffeine or no) is just the ticket to finish #3.

share|improve this answer

Please see this related post in Skeptics.SE: Is the Ballmer Peak real?, and in particular this answer by ESultanik.

Why do I think these two questions are related? It seems to me that the impairment caused by sleep-deprivation is somewhat similar to getting drunk, although I do not have any references to back up my claim.

Quoting from ESultanik's quoted reference,

...modest alcohol consumption inhibits aspects of creativity based mainly on the secondary process (preparation, certain parts of illumination, and verification), and disinhibits those based mainly on the primary process (incubation, certain parts of illumination, and restitution).

I would say that one may be better at creating abstract architecture models while sleep-deprived, but the actual source code typed into the keyboard would still be inebriated.

share|improve this answer

When one is forced to code for 36 hours, it's usually because of a deadline to ship the product. When one is on such a deadline, code quality is typically the first thing thrown out. "Just get it done" is the mantra. "We'll fix it in version 2" is another mantra.

So typically, when one is coding for 36 hours straight, code quality does suffer.. but it doesn't matter from a business standpoint.. because if you don't ship something, even a broken something, you might not be in business to do it right.

When one WANTS to code for 36 hours straight, it's because you have a strong creative spike going, and you don't want to interrupt it. You won't be writing quality code for that 36 hours, but you will be writing creative code. You then come back later and look at that code and wonder how it even works.

Creativity is one of those things that often comes in spurts. You can't control it, so you take advantage of it when it shows itself. You can always fix the code when you're less creative.

share|improve this answer

A few months ago, I was out with my co-workers drinking. The next day we arrived back in the office hung over... but to our amazement we closed off a record breaking amount of bugs.

On the surface, these bugs were not easy to find and most did not have any steps of replication, however still being 'out of our minds' must of made us 'think out of the box' when it came to fixing the bugs.

Although we were not 'sleep deprived', we were still not in the right mindset for working on code... its just bizarre what happened that day, we always mention it.

Oh, and for the inclined most of us were maxing out on JD & Coke :)

share|improve this answer

I think working productively for so long without any sleep long is impossible for most people.

But I think you can do amazing work with just, say, 3-4 hours of good sleep. This works even for several consecutive days of intense (intellectual) work with little sleep.

However, for me, this must be followed by a recovery period afterwards; say, a couple of nights with the usual 7-8 hours of sleep.

share|improve this answer
