DEV Community

Gulnur Baimukhambetova
Gulnur Baimukhambetova

Posted on • Edited on

2

My first refactoring!

Hello everyone!

Today, I have practiced refactoring which is basically reworking your code for a better quality of it. It also means that to alteration are done to the logic itself but to the structure. It can include renaming the variables for better readability or extracting functions for better maintainability.

As always, I have pulled the latest repo version and created a new branch to work on this. Shortly, I:

  • removed repetition by requiring specific functions instead of whole modules
  • standardized error logging styling by creating a logErr() function
  • re-used my functions inside other helper functions
  • separated HTML files creation logic from input logic
  • renamed file names for better readability
  • removed unnecessary variables creations.

I did everything as a separate commit but then I squashed them together using interactive rebase. So, I could merge only one nice commit that holds all the changes.

Unfortunately, at the end, after I have already pushed the changes to GitHub, I found a bug in my code which I had created while refactoring. I decided that it was better to make the changes and somehow add them to the previous commit as it does not make sense if it creates a major bug. Plus, thus no one would know that I created something that I had to fix later. It would look nicer in history, almost if everything worked like magic right away. For that I added my changes and committed them with amend option. However, I had to push with force later as the git would complain about me making dangerous changes to the history.

Overall, it was great to go back and pay my tech debt.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay