Blog
July 19, 2026 • 3 min read
The First Time I Had to Seriously Refactor My Own Code
Writing code that works is satisfying, but maintaining code that has grown messy is a different challenge. Refactoring my own projects taught me why good software needs continuous improvement.
Tshepang M. Kgaphola 
Published • 4 months ago

Image source: Unspecified image source
One of the interesting moments in development is returning to code that I wrote months earlier. Sometimes I am surprised by how much I have improved. Other times I immediately see things that I would structure differently today. That experience taught me that refactoring is not a sign that the original work was useless; it is part of developing software over time.
Working Code Can Still Be Improved
The fact that an application works does not mean the implementation is ideal. Code can function correctly while still being difficult to understand or maintain. Reopening an early version of my portfolio's routing logic, I could not immediately explain why I had written it the way I had, even though it technically still worked. That is the kind of detail that is invisible right up until it is not. That single experience changed how I approach similar situations today.
I Notice Different Things Now
As I learn more, I recognise patterns and problems that I would not have noticed when I originally wrote the code. Refactoring gives me a way to apply that newer understanding. A pattern I would now recognise instantly as unnecessary complexity looked completely reasonable to me at the time I originally wrote it. That shift in thinking has quietly carried over into almost everything I build now. That was the moment the idea stopped being theoretical and started being practical.
Duplication Becomes Expensive
Repeated logic may be convenient initially, but changes become harder when the same behaviour exists in several places. Refactoring can reduce that duplication and make future changes easier. The same validation logic, copied across three separate forms, meant a single rule change had to be made in three different places until I finally consolidated it. I would not have taken this seriously without running into it myself first. It is a lesson I now pass on to myself before I even need to relearn it.
Naming Can Improve Everything
Sometimes refactoring does not require changing the architecture. Renaming a variable, function or component can make existing logic much easier to understand. Renaming a handful of vaguely named variables, without touching any logic at all, made an entire file noticeably easier to follow. I catch myself returning to that idea whenever a new project starts to grow. That single afternoon taught me more than several weeks of reading around the topic had.
Large Refactors Need Care
Changing too much at once can introduce new problems. I have learned that smaller, understandable refactoring steps are easier to test and reverse. Attempting to refactor my entire routing setup in one sitting left me with a broken build and no clear way to tell what had actually gone wrong. None of this felt important until the moment it actually mattered. I try to remember that lesson every time a similar situation starts to appear.
Refactoring Is Not Rewriting
A refactor should improve the internal structure without unnecessarily changing what the application is supposed to do. Rewriting everything can be tempting, but it also introduces a lot of new risk. Refactoring my blog's data-fetching logic changed how it was organized without changing what it actually returned to the rest of the app, which was exactly the point. It took living through it once for the idea to actually stick. That single change was small in code but noticeable in how the project felt afterward.
Old Code Can Teach Me
Looking at older projects is sometimes uncomfortable, but it provides a record of my development. It shows me which problems I used to struggle with and which patterns I understand better now. Looking back at that early code now feels less like embarrassment and more like a fairly accurate record of how much my own understanding has grown since then. It sounds small written down, but it changed a real decision at the time. I still think back to that specific moment more often than I would have guessed.
Blog & Newsletter Information
For blog updates, article questions, topic suggestions, or other newsletter-related inquiries, contact newsletter@tshepiem.dev. By subscribing, you agree to receive blog updates, new article notifications, and occasional newsletter emails in accordance with our Subscription Terms. You can unsubscribe at any time using the unsubscribe link included in our emails.