Lab5: Refactor the code to improve maintainability
Thanks to the people's contributions to my link-checker command-line tool named url-fi, my tool gets a huge improvement. However, it has some coding style inconsistent because my code has other people's code as well. I took some time to walk through my link-checker tool and made some refactoring.
There are five commits I add to improve my code
- Move the global variable to the top
- Add comments to the variables and functions
- Rename variable name
- Erase unnecessary code
- Update help message
Firstly, I found some global variables named rFlag, ignore, ignoredLink was located in the middle of the file. Therefore, I move those variables on the top of the file. Secondly, I added comments to the variables and functions so other people can easily get what my code is. Thirdly, I renamed variable names ignore to iFlag to make the variable name consistent. Fourthly, I erased unnecessary code. There was code duplicate that the process.exit(1) and the process.exitCode=1 was written in a row. As the process.exit(1) already made the process.exitcode 1 and then exited the program, the process.exitCode=1 is unnecessary. Finally, I got the help message my tool display is out of date so I updated the message.
The git log after I've committed all the commits are the following.
I rebased the commits to squash those five commits into one commit and these are the images to squash them. I entered 'git rebase master -i' to squash them.
The git log after I've squashed all the commits is the following
The git log after I've amended my commit is the following:
The merge commit URL after I've merged my refactoring branch is the following: https://github.com/hyunjiLeeTech/URL-FI/commit/e7bcb976c0a703e504a0ad15ad8e3659c4739079
I did not get any errors and conflicts to follow these steps. Also, the concept of refactoring was interesting. I felt it is powerful. Also, I did not know I can amend the commit message so the process of the rebase and the amend message was really impressive. I had confidence I can do better in the future when I need this knowledge.
Comments
Post a Comment