DEV Community

Gulnur Baimukhambetova
Gulnur Baimukhambetova

Posted on • Updated on

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.

Top comments (0)