DEV Community

Cover image for Refactoring, and Rebase
Hung Nguyen
Hung Nguyen

Posted on • Updated on

Refactoring, and Rebase

Refactoring codes

This week is a good time for me to take a look back at my project to make some improvements. My program is working as expected but my codes are not clean and optimized. There are still a lot of redundant codes of testing stage, repeating codes and some ambiguous variable names.
Firstly, I created a new branch name refactoring then wrapped all duplicated codes up into a function. Then call that function in appropriate places. Variable naming is important in professional programming. It makes your codes more easily to understand when other people try to read them or when you want to look at your codes to make some changes. If you name your variable a which stands for array, other people might misunderstand it and they might think a is argument. This also the same with naming functions. In the end, all the names of variables and functions are now more clear and understandable. Lastly, I deleted all the console.log that I created while testing to make my code neat and look more professional.

Git Rebase

Each time I finished an improvement, I committed that step. After testing my tool many times to make sure it still works, I git rebase main -i to move my recent commits to the top of the sequence of commits. With option -i, my command will do an interactive rebase to allow me to choose what to do with my commits. I picked pick for the latest commit and the others are squash so that they will attach to one commit only. Finally, I did git commit --amend to modify my latest commit last time and merge the refactoring to main then push.
Git rebase is beneficial for maintaining a clean history of your project. With git rebase, your branching workflow is easily visualized, since you can rebase your old branches to the top so that you can start fixing and debugging your codes with ease.


Github repo:
Final Merge commit:

Discussion (0)