Prince Kyei’s Post

Most bugs don’t come from what you write… They come from what you remove. I used to think deleting code was always a sign of improvement cleaner, leaner, better. Until I broke production by removing something I thought was “useless.” Turns out: • That “unused” function was handling an edge case • That “extra” check was preventing a silent failure • That “old” logic was protecting against bad data Now I follow a simple rule: 👉 If you don’t understand why it exists, don’t delete it yet. Refactor it. Trace it. Test it. But never assume it’s useless. Because in software… Sometimes you're not cutting dead weight you're cutting the branch you're sitting on. If you’ve ever broken something by “cleaning up” code, you know exactly what this feels like 😅 #SoftwareEngineering #CleanCode #Programming #Debugging #Developers #TechLessons

  • diagram

I'm going to disagree with you on the classification that removing code is where most "bugs" come from. Removing code that you are not 100% sure can/should be removed and a problem occurs is usually uncovering a bug that was hidden - It already existed. Or you failed to trace its need.If you are not sure if an "uncalled method" is being used, add tracing. I had a team recently inherited a project that had several public API methods marked with Obsolete - The question is at what point can we removed them. No one on the team was around when they were marked, so the team added logging and created a dashboard so that they can monitor this over a specific time frame. Once they are satisfied it is no longer being used, they will plan for its removal. For those still being used, the logging includes identification information to help have the conversation with the owner of the consumer. Being able to remove code does make it better by reducing the maintenance requirements. Knowing what can be removed can take more than just looking at the code, it takes actual research which sometimes will need to happen over time.

There is a reason why software architects unit test their entire system, so that we can remove code with confidence because if the tests are properly written, and they still pass after the code is removed or refactored, then the code base functionality is still preserved.

I had a friend who deleted a few lines of code during his first week at our company, and he almost got fired for it. It turned out those few lines were responsible for triggering the payment modal 🤣

That's what source control is for 😁

Prince Kyei That feeling when you delete something you think is useless and production breaks. Turns out that useless block was holding everything together. Great reminder. 😂

Deleting some block of code that I think is useless just now 🥶

See more comments

To view or add a comment, sign in

Explore content categories