Refactoring is about improving my code's structure, making it more readable, and enhancing its performance. It's a crucial skill for any programmer.
This time I refactored my open source project code ConvertTxtToHtml. I mainly did three improvements.
First, in the beginning I created the project name when it can be only used to convert txt file to html file, after a few week's work, my script can also convert markdown file to html file. So I change my script name to convertTxtMdToHtml which is more suitable to it's usage, and I also changed the output directory name.
Second, my VSCode threw a warning message about not using a package, so I deleted it to remove the warning.
Last, I have some constant variables in my old code which are only named in lowercase letters or directly using the Sting between the codes. In order to improve it, I tried to use the uppercase letters and put in the front of the main function.
After improving my codes, I used Interactive Git Rebase to squash all of your refactoring commits into a single commit, and set the first one pick, the others squash to combine all my three commits.
git rebase main -i
I also used Amended Git Commit to update my commit message.
git commit --amend
and merge, push my work
git checkout main
git merge refactoring
git push origin main
Refactoring code was an awesome experience, and it's something I plan to do with all my future projects. It's like giving the code a makeover and making it shine.
Top comments (0)