Does anyone else function that way?

Like whenever I try to do something, like programming I can never get myself to start it, and when I do I constantly get distracted by stuff. And sometimes, when there is a few hours to finish I somehow clutch up and do all the stuff flawlessly in like 1-2h. Anyone else works that way? And how?