DEV Community

Cover image for 5 Things I Wish I Knew Before Refactoring App or Project
Kok Wui Lai
Kok Wui Lai

Posted on

5 Things I Wish I Knew Before Refactoring App or Project

refactoring code is not just challenging also for me it was a thing that always excite me to do because its fun and it challenge myself to solve problem differently, compare the performance.

But hold on, do you really have to do this yet? Are there tasks that is more important that is not complete yet?

refactor is not always needed, time is precise, is it worth it? does it really make a different?

here are 5 things i wish i knew before start refactoring

1. Check your Safety Net

Does your feature have unit tests? is your unit test really matters? Have you consider those edges cases yet?

Based on my experience back when i first time bring the project live, first 5 minutes is totally fine until someone tested the feature with the input that i never thought of and causes a lot of chaos which lead to data corruption and data loss.

If refactor distract you from doing the most important job. you need to stop refactor first.

2. Ignore Legacy code unless you are forced to

"If code works please do not touch it!" This is what i ignore because i find it hilarious and i dont believe it.

refactor legacy code is like trying to fix a broken vase that fixed by tape. There's domino effect that can crash the whole production. Don't hurt your reputation and your relationship with your teammate.

3. Do a benchmark first

not all legacy code is bad code, maybe is just a me problem, its not written the way i want, is not the right way of using the lib/function.

If benchmark result is terrible, refactor not always a good choice, starting from scratch wins all the time because legacy code could tie you up and lead you to dead end.

sweep all the stuff off from the messy table at one go and start from zero is always faster than rearranging messy table.

4. Is a trap, you have OCD

have you ever rewrite a big black box of code for few days and end up the whole flow is not much difference? I know i have, not only that, i didn't fixed the pain point even though i felt accomplished from understanding, fixing, rebuild it. Now that block of code is like a flower vase that smell like rafflesia.

Would you rather have a patched broken vase that match with the flower or a fancy vase that doesn't match with the flower?

5. Just don't do it

I had too many bad outcomes and experiences after doing refactor. 99% of the time i can just let it be, recall yourself at work, how many times you have to refactor code? not even 1%. most of time starting from scratch is easier and its easier to revert back when something goes wrong.

In conclusion, save your energy for more exciting stuff, building new feature, strengthen your safety net, save yourself hours of life for better stuff out there. :D

remember refactor is optional, if code works don't touch it!!!! please don't give more problem to your boss that have to always deal with clients.

Top comments (0)