I don't have much experience in working in software industry, being a self-taught and having participated in open source before deciding to take a job. Now that I work for money, I also have to deal with some unpleasant stuff, which is normal of course.
Recently I was assigned to add logging to a large SharePoint project which is written by some programmer who obviously was learning to code in process. After 2 years of collaboration, the client switched to our company, but the damage was done, and now somehow I need to maintain this code.
Not that the code was too hard to read—each project has one class with several copy-pasted methods, enormous if nestings, Systems Hungarian, undisposed connections—but it's readable.
However I found myself absolutely unproductive in doing such simple task as adding logging. Basically, I just need to go through the code step by step and add some trace calls. However idiocy of code is so annoying that I get tired each 10 minutes. In the beginning, I used to add using constructs, reducing nesting by reversing if's, renaming the variables to readable names—but the project is large, and eventually I gave up. I know this is not the task I should be doing, but at least reducing the mess gave me some kind of psychological reward so I could keep going. Now the trick stopped working, and I have 60% to do yet.
I started having headaches after work, and I never get this feeling of satisfaction which would usually allow me to code for 10 hours straight and feel fresh.
This is not just one big rant, for I really do have an actual question:
Is there a way to stay productive and not to fight the windmills?
Is there some kind of psychological trick to stay focused on the task, instead of thinking “How stupid is that?” each time I see another clever trick by that fellow? The problem with adding logging is that I actually have to understand what the code does, and doing so hurts my brain in an unpleasant fashion.