Over the last few years I have felt a drastic and surprising improvement in how I feel about work. I can trace a lot of this benefit to one simple technique.
Get stuff out of your head
I didn’t think it mattered that much. When I first read Getting Things Done, I didn't really grasp the power of closing open loops and how free that left me to not only focus on my current task, but also forget things—temporarily, of course—that would otherwise worry me night and day. (I'm the type to worry, so generic advice to "let things go" never really worked for me.) When I started getting things out of my head onto paper, into spreadsheets, wherever… I felt much more relaxed, sped through tasks at full focus, and that generally made everything feel better.
You don't need to do much to start feeling the benefit of getting things out of your head. Try this.
During your next task, put some paper and a pen next to you. While working on your current task, whenever something pops into your head not directly related to the task at hand, write that down quickly, then get back to your task.
This will feel strange at first.
Stay with it. Keep doing it for the entire time that you want to focus on your task. When you finish your task, place the paper in your inbox. If you don't have a physical inbox in your work area, it takes 10 seconds to create one: find a tray, a box, a file folder, anything that stores paper, then label it "INBOX".
If you noticed that you need to do something on this newly-created list today, then scratch it off your list and do it today—now, perhaps. Otherwise, let the page sit in your inbox until tomorrow. Forget it the best you can. (You won't do a good job of this yet. Go easy on yourself; you're learning.) Practise this for two weeks. Use a tracking tool like http://mercuryapp.com to track how stressed you feel about the stuff you've put in your inbox.
Each day, before you do any other work, spend 2 minutes looking through your inbox for anything that you need to do today, then scratch it off the page and do it today—now, perhaps.
Specific advice for programmers
Kent Beck taught me about "test lists" and I use them every time I program. Before I write my first test I make a list of the tests I think I'll need. Once I get those out of my head, I choose a test and start programming. As I work, if I think of a way to refactor the code, I write that down on my test list, then get back to the task at hand. If I think of more tests to write, I wrote them down on my test list, then get back to the task at hand. This helps me focus and avoids a lot of stress.
Specific advice for pair programmers
When you're not typing, you get to think about where the design appears to want to go. You have ideas about what to do next. You must, however, let your partner—the one typing—focus on the current line of code. When an idea pops into you head, write it down. You can do this without disturbing your pair partner, and you won't forget anything. Let your pair partner focus!
When I try to write down an idea that has leapt to my head, if I have trouble writing it down succinctly, then I probably don't understand it very well, in which case I can safely forget it. This lets my subconscious mind work on it, and when it comes back to my conscious mind, it usually comes back in a form I find much easier to write down succinctly. I find that helps me avoid trying to do ill-define things with no real goals.
Another unexpected benefit
I love crossing things of my list, whether because I have completed them, or because I've decided not to do them. Both acts helps me feel freer; perhaps they'll do the same for you.