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.