DEV Community

JLi
JLi

Posted on

Refactoring LENNAH SSG

This week we learned about refactoring and combining commits using Git. As I have mentioned in my first blog about LENNAH, I wanted to make my SSG in C++ because I wanted to practice my C++. Our projects were meant to be pretty rough around the edges and messy to begin with so we would have a lot to improve on. So I figured using C++ would be perfect for that. And indeed it has given me a lot of code to refactor.

When I originally started off with this project I didn't have many separate files, everything was done under a single cpp file. So I had a lot of code I would need to split, because it was becoming extremely crowded in my single cpp file. It also had a lot of features added from my classmate Andrew, who added to my repo with config file support last week. If you want to see what he did here's a link to his blog post.

First thing I need to do was update and add some of my function descriptions in the code comments. There were a few descriptions missing from some of the features both Gus and Andrew previously added that I touched upon. I also had to update the naming for my readTxt() function because it now also can read .md files so I changed it to readFile(). Then I extracted a function to delete and create an output folder because I noticed that this was done twice in the code. Additionally, I had to update some console outputs for the config file support feature Andrew added.

Once the code clean up and adding of comments was done, it was time for me to split my code and create header files for my classes and functions. This was the hardest step for my refactoring because I had to completely restructure my code. However, once it was done my code became a lot easier to read and also by doing this I was able to simplify some code that was actually repeated by removing the repeated instance completely.

After I tested everything I was able to do an interactive rebase in Git to merge all my commits together. This was a really neat feature that allowed me to keep my actions/changes organized and it was super easy to do! If you want to take a look at my rebased commit you can find it here. While it looks like a lot was changed it was a lot more manageable because in reality it was a bunch of separate changes. This feature is great to make the commit history look a lot cleaner because I know I am someone who always tends to miss a few things here and there so the tiny commits tend to pile up. Now I don't have to feel as bad when I notice a small thing that needs changing, I can just rebase the commits!

Well anyways thanks for reading, and as always, take care!

Top comments (0)