DEV Community

Tong Liu
Tong Liu

Posted on

Reflect on Lab 5

What is lab5 about? Why do I like Lab5?

In this week's lab, we are expected to improve the quality of our code by refactoring them, and also; we are going to use lab5 as a chance to understand and practice the git features of --amend and rebase -i, so that we know how to add something to the previous commit without creating a new one. I think this week's content is especially useful, because sometimes I don't want to get my commit log littered with commits all over the place, rebase and amend are exactly the features I've been looking for in Git.

What have I fixed and how did I fix them?

In this lab5, I was focusing on the code redundancies to eliminate them, as well as fixing some logic to make them more readable. The first thing I started off was making each class do their own jobs(called "Single Responsibility Principle"), to make this happen, the class I fixed first was ArugmentQueue, because this class is supposed to read arguments and call functions to parse the files accordingly, however, it was mixed with the code that for file reading in my previous implementation, to fix that, I extracted the file reading code into some public functions in a class named FileProcessor, also the code that print error messages, version, and help, was moved into a class named MeesagePrinter. ArgumentQueue holds these 2 classes as member variables and initializes them in the constructor, whenever the print functions or file reading functions are needed, just call functions on these 2 member variables accordingly.

How did I commit my code and what git command did I use?

I made several commits in refactoring my code and each commit I made was pretty small. To combine different commits into one single commit, I used git rebase -i which allows me to squash(Git actually calls it this name) commits into 1 commit and with -i(means interact) it will give me a chance to edit the final commit before forging it. In the process of the base, I removed all previous commits by putting squash in front of them, after exiting the editor, the rebase was completed. Soon after that, I checked if the unwanted commits were actually removed by using git log, luckily, the rebase command worked as I expected since only one commit was shown up. However, when I tried to push it to the remote by using git push origin main, git showed me that the origin repository did not exist, but it works when I use git push, I googled it a little bit trying to fix it, as the result shows that I didn't add the upstream to the origin, I realized I initialized the local git repository in a wrong way, however, this was fixable simply by using command git remote add https://my_repo_addr.git, after using this command git push origin main seemed worked fine.

Top comments (0)