DEV Community

JLi
JLi

Posted on

1

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!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay