How to stay productive when dealing with extremely badly written code

code-qualitymaintenanceproductivity

I don't have much experience in working in software industry, being 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 on the job. 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. Despite problems—each project has one class with several copy-pasted methods, enormous if nestings, Systems Hungarian, undisposed connections—it's still readable.

However, I found myself absolutely unproductive despite working on something as simple as adding logging. Basically, I just need to go through the code step by step and add some trace calls. However, the idiocy of the code is so annoying that I get tired within 10 minutes of starting. In the beginning, I used to add using constructs, reduce nesting by reversing if's, rename 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 still have 60% of my work to do.

I started having headaches after work, and I no longer get the feeling of satisfaction I used to get—which would usually allow me to code for 10 hours straight and still 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 the previous programmer? 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.

Best Answer

I'm sorry to tell you, but not all jobs are full of sunshine and glamor. The majority of development tasks involve drudge work like this. Sad, but true.

You are tasked with an important job, even if it's boring to the point of watching paint dry. It's important for two reasons: 1. It add much needed logging to a large system so that when something goes wrong you'll have a tool to help you find it. and 2. It gets you familiar with the code base so that if and when something goes wrong you can jump in and fix it.

You are basically creating your own safety net here. Glamors, no, but important yes!

So, that being said how should you motivate yourself? When I have a mind numbing task at work, I set goals for myself. Finish doing task x by the end of the week. If I make my goal, I reward myself. New restaurant I want to try? Go Friday night if I finish. New movie just came out? See it on the weekend if I finish.

I find talking with my supervisor and letting him/her know where I'm at and how I'm progressing keeps me accountable. If I tell them I'll be done by Friday, I feel more inclined to get it done by Friday b/c I told them I would have it done.

Keep faith that once you complete this task and you've done it well, on time and on budget that people will notice and when that shinny new project comes along, your name might just be suggested as the one who gets it. :)

Related Topic