DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

Collapse
 
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.

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.