DEV Community

dbelokon
dbelokon

Posted on • Updated on

Refactoring Marathon and Rebasing Torturing

This week I was doing some refactoring for my glazed-donut repo. Since its creation, the features kept coming in every week, but there was no refactoring done whatsoever, so... it got pretty messy😅

Tom cleaning

Refactoring

It took me a while to come up with a way to refactor glazed-donut, because all the code was written in one file from the beginning😵. From this, I decided that I would focus on refactoring it into classes this time.

First, I decided to create a file handler and a directory handler classes to manage their specific cases (i.e when the file path name is a single file or when it is a directory). This way, I separated two main functionalities of my ssg into separate files, so it is more clear and organized.

I also thought that creating a common parser class would be a great addition, since it would help to differentiate between different ways to parse from a text file to an HTML file.

Next thing I did was adding another class to manage the parsing class dependency, such as opening the file, and outputting the HTML string from the file.

Lastly, I implemented a common interface across file and directory inputs.

I am still not fully satisfied with the refactoring, but as my professor always says - code is never finished🙂 So I will still keep improving it over time. I also realized that OOP approach is very handy when it comes to refactoring. It helps us to have a better organized code base.

Git process: Commiting, Rebasing, Pushing, Merging

After each refactoring stage, I would make a commit so I had a chance to revert a specific commit back if anything went wrong.

Rebasing has given me a couple of heart attacks last week, not gonna lie🤯 But after some torturing and a dozen of fallen hair, I decided to ask my classmates for help, so luckily, it all worked out😋 So after I finished all the refactoring I wanted, I decided to make an interactive rebase on master branch, and squashed all of the commits into a single one.

After that, I pushed the changes to my origin repo, creating the refactor branch

Then, I create a PR to merge everything into the master branch. Here is how it is looking now.

Byeeee

It was nice to get to know another Git feature - rebasing, that helps to organize commit history. I was also really happy to finally get some time to refactor my repo.

Discussion (0)