Bad Code Can Make for Good Learning?

twitter logo github logo ・1 min read

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?

twitter logo DISCUSS (1)
markdown guide
 

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.

Classic DEV Post from Nov 3 '18

Which trend or advancement is being overlooked by most developers?

What is the most underrated movement that could have a real affect on software?...

Thomas H Jones II profile image
Been using UNIX since the late 80s; Linux since the mid-90s; virtualization since the early 2000s and spent the past few years working in the cloud space.