DEV Community

Thomas H Jones II
Thomas H Jones II

Posted on

Bad Code Can Make for Good Learning?

Anyone else find that, when they encounter really horribly written code they've been charged with cleaning up, refactoring, etc., that the very the act of trying to sort out the prior programmer's spaghetti-code basically forces a deeper examination of the code than had the code been better written in the first place?

Top comments (1)

mrwesdunn profile image
Wes Dunn

Oh the joys of inheriting and maintaining a legacy codebase!!! Whether or not this question was inspired by a legacy codebase, the pain of inherited spaghetti-code definitely resonates with me. I have often remarked that my title should be code janitor. 🤣

As for the question, YES, ABSOLUTELY!!! Throughout the past few years, I’ve been tasked with refactoring and adding new features to a handful of applications that share a lot of the same C++ code (not modern c++ either, mostly C code that makes use of classes). As such, I’ve wandered into “dark corners” of this code that has befuddled me for days, but thanks to the excellent tooling Xcode provides, I’ve been able to grok the functionality of the code and get a sense of how that/those piece(s) of code interrelate to the entire application. Despite the all-too-often “WTF!?!” reactions to what I find, I believe it has been incredibly valuable to my overall domain knowledge, ability to identify code smells, and “how not to do things next time.”

Unfortunately, I think there are a lot of pitfalls to this kind of position. For me, it’s resulted in reusing other poorly written classes/methods/etc as a kind of “crutch,” in that those things can become excuses to not refactor things further than the scope of the work.