Having said that, back when I didn't understand this I did figure out that it was a waste of time to stay up literally all night. At 3am or 4am you should go to sleep for two or three hours.
But, I was young, then, and those projects were relatively limited in scope. I didn't know at the time that ADD existed; this was just the way I'd found to get such things done. (And I hated all the fear and dread it put me through.)
So, it may not be an optimal approach, but in some circumstances, the all-nighter can perhaps be enabling.
But if an all-nighter is truly the only option, then 20 minute naps every 2-3 hours works well combined with a cup of coffee.
Method: Drink a cup of coffee, immediately nap for 20 minutes, wake up and work for 2-3 hours. Rinse and repeat.
There is the counterpoint of hyperfocus. Something that is intensely interesting -- whether due to the topic itself or consuming pressure to get it done (NOW!) -- also lessens distractibility.
http://www.physorg.com/news93623459.html
So, take my comment with a good grain of salt. If I find a relevant reference, I'll follow up.
A memorable one was a software upgrade to Cascade switches at AADS. Turns out the new firmware consumed more RAM than anticipated and we ended up with 10's of thousands of circuits down throughout their network of ~250 backbone switches. I spent 3.5 days straight with nothing more than a couple of two hours naps and LOTS of pizza, coffee, soda, etc. The magnitude of the situation pretty much prevented me from sleeping. Had a couple of other 36 and 48 hour shifts during that same job. Every time I've done any marathon sessions, it was always unplanned and urgent.
And don't pull all-nighters, you're much better off getting some sleep if not a full 6-7 hours.
Of course, as most posters point out, actually sleeping is always best, but sometimes it just has to be done.