Don't judge yourself by the great code you've written today.
Programming is so much more than cranking out great code.
Find out why you don't feel productive.
For me personally, it's usually one of the following:
- fixing non-code problems (such as build tools acting up, servers offline, etc.)
- planning/meetings with only vague results ("we have to fix this somehow - this is important!")
- finding five new bugs while trying to fix one
- being janked out of the flow with a totally important new idea
- some customers...
At the end of such days, I make a mental list of what I did today before I get home. This helps me shed the vague feeling of having spent an unproductive day.
Your problems might be different, so might be your solutions:
Just can't understand the code? Maybe you lack some form of better documentation.
Unsure what do do right now, or not confident that what you do is worth the trouble? That's often caused by bad management, can be fixed by better planning - you need clear milestones with easily tested goals. if you don't get them, set them for yourself.
Solution is more complex than you thought?
This can be caused by bad planning, or the anchoring effect (Someone expecting a solution in five hours makes us think it can't take longer than five hours - even if we know he can't tell a for from a fork, and even if we are aware of that effect. )
Don't try to solve all things on your own
Many of these problems involve your coworkers and your manager.
Have a list of other things to do
There are often low priority maintenance tasks, that get delayed and pile up. Having such a list might give you something more productive on days where you can't focus.
However, if you do that, also track the time spent on these low-priority tasks. Otherwise, you are just delaying your procrastination crash.