Programming is about narrowing your focus. The narrower you can get it, the easier you'll find it. Focus on one part and blaze out the code, then move on to the next. If your underlying design is sound, you'll get a good program. Of course there's a whole lot of recursive subfocusing but we won't talk about that right now.
When you're well-rested your mind runs fast, and you have to hold it still to focus on anything for long. Sometimes this happens easily and you write a bunch of good usable stuff. Sometimes it doesn't and you spend the day goofing off. (Yeah, it happens. Went through about half of the SA game reviews one day. Just couldn't focus.)
When you start getting tired you start getting hazy. You make dumb mistakes, you spend more time goofing off.
After a while all your excess energy is spent. So you buckle down and code.
You're tired enough that it's not hard to keep in line, and you're still awake enough that you can write good stuff. It's not brilliant stuff - I wouldn't want to try maintaining my compression algorithm in this state - but when you're hacking at something that's just slow going, it's nearly ideal.
It's been too long.
And then, ideally, a song comes on that *really* makes you grin, and it's all good from there.
but my fingers catch the sparks
at the thought of touching you