Maintaining Bad Code Can Be A Great Experience

12 commentsWritten on September 4th, 2011 by
Categories: Opinions, work/career

Nobody likes to maintain a bad codebase. And still, it's an experience that i'd recommend to every developer, particularly early on in your career. People who are relatively new to coding usually don't have a good view yet on what kind of code will cause pain in the long run, and what kind of code won't. And if you keep getting assigned to new projects, you're less likely to develop that view properly compared to someone who has to maintain an existing, problematic codebase.

We've all heard the most common ways of improving as a developer: read the right books, learn from more experienced people, and above all: practice, practice, practice! And all of that is indeed very important. But i've always felt that being exposed to bad code and having to deal with it can be a tremendously important and valuable learning experience as well. As valuable as repeated practice, reading and following advice from experienced and skilled developers is, none of it will stick with you as long as the pain you feel day in, day out from working with a bad codebase.

When you're working with a bad codebase, it's important to figure out where the pain comes from. Whenever you experience pain while trying to make a change, or while trying to implement a new feature, take a bit of extra time to look for the cause of the pain. Then try to think of a way that would avoid the pain entirely, or at least lessen it. And if you can, implement your solution in the codebase. If you can't, try the approach you thought of in a personal project. If you do this routinely, you're going to learn a lot about what works well and what doesn't. I'd dare say that you'll get a better view on this than people who never have to work with legacy code, since they rarely get exposed to the long term problems caused by the code they write.

  • Kristof Rennen

    I agree, I think it even learns you more in the end than always working in the newest technologies and the cleanest architectures and code bases.

  • http://twitter.com/JefClaes Jef Claes

    I absolutely agree. One of the first projects I was assigned to was a nightmare, I was like “It can’t/shouldn’t be like this, right?”. In hindsight, it probably was one of the experiences I’ve had so far. You really are _forced_ to think about why it sucks so bad. It’s very rewarding to try out small changes, and see your developer happiness increase.

    On the other hand, I see people, who just grind it out.. But that are mostly the not-so-passionate devs, who should consider changing careers ;)

  • Filip Duyck

    I think it can go both ways — I’ve seen good developers pick up bad habits from horrible codebases simply because they were “acceptable” compared to how bad the rest of the codebase was.

    That being said, I think I learned a think or two from maintaining bad code :-)

    • http://davybrion.com Davy Brion

      if developers pick up bad habits due to it being acceptable for whatever reason, a bad codebase isn’t the only thing that will steer them in the wrong direction

      • Filip Duyck

        Indeed, it won’t be. But it doesn’t hurt to make sure there’s some mentoring going on when letting a new developer wade through a bad codebase ;-)

  • http://bramdemoor.tumblr.com/ Bram De Moor

    What works best for me is to do maintenance work for 1 or 2 days a week, and do ‘new’ development on the other days. This makes the maintenance work more bearable. It keeps you motivated. And if you’ve been working on the brand new super-codebase for a while, it’s always great to get a reality check or motivation boost by working with crap code.
    In any case, the trick with maintenance work is indeed to find a way to make it work, to slowly improve the codebase and to learn. Just grinding it out is always a bad idea.

  • http://davesquared.net David Tchepak

    “If you can’t, try the approach you thought of in a personal project.”

    This is one thing I’ve really struggled with. When working with large codebases, testing out alternative ideas on personal projects just doesn’t seem enough to give me the confidence to scale it up to much larger projects.

    While on that topic, any tips for picking good personal projects that are complex enough to provide insight but simple enough to get done in spare time?

    • http://davybrion.com Davy Brion

      for personal projects: the only thing that matters is that it’s something you can maintain interest in long enough to keep working on it

  • Anonymous

    I agree, I would almost go as far as saying you need to stick with a codebase long enough, for the bad code you wrote previously to come and bite you. It’s definitely good to have your poster project of how not to do things. On our main legacy project we’ve had learning like, avoid using the GAC, don’t backport .Net 2.0 features to .Net 1.1 it makes for a bad codebase. If it takes a new dev days to get up and running, there’s something seriously bad about your codebase.

  • Bigolewannabe

    I’ve thought since before I graduated from college that at least one semester should be a maintenance programming class where the professor dumps an intentionally horrible codebase on a class. Their role is to fix issues as they’re “discovered” and whatnot.
    The normal capstone class is greenfield and I found it didn’t really reflect the reality we would (and I did) experience.

  • George Entenman

    Maintaining code can be “great experience” but it’s not “a great experience”.

  • http://developeradvocate.appspot.com David Nelson

    Hey Davy.  I agree as well.  To reflect on a lesson in the book clean code, I find it helpful to follow the “Boy Scout Rule”.  Always make the code you are working on a little better than how you found it.  What I found is that by doing that for a while, it becomes easy to implement a refactor to make the code maintainable at the same time you are fixing bugs and adding features.

    This is a mental shift.  Instead of thinking “I hate this code.  Why do I have to work on this crap”, you reframe it in your head to “This is such a great opportunity to make this code maintainable!”.  :-)