DEV Community

WangGithub0
WangGithub0

Posted on

1

Refactoring my code

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.

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

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

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

Okay