DEV Community

dbelokon
dbelokon

Posted on • Edited on

1

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.

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

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay