Refactoring: My Journey Through Lab 5

madhur Saluja - Oct 12 - - Dev Community

Lab 5 was all about taking a messy codebase and turning it into something clean, modular, and dare I say, beautiful. Refactoring, they said, would be fun. Did I believe it at first? Nope. But spoiler alert: it kind of was.

Step 1: Breaking Up the Party

The first thing I had to do was separate concerns in my code. Imagine having a party where all your guests—file parsers, argument handlers, and AI managers—are in one giant room, all talking at once. Yeah, it gets chaotic.

So, I kicked some guests into their own rooms, separating the command-line parsing from the rest of the chaos. Now, each piece of logic had its own space to breathe, making everything way more manageable (and quieter).

💡 Commit Message:

refactor: separate command-line parsing from AI logic and output
Enter fullscreen mode Exit fullscreen mode

Step 2: Naming Things Like a Pro

Now that the party was under control, it was time to give everyone a name. And not just any name—good names. No more “data” and “config.” Oh no, we’re talking meaningful, descriptive names like “request_payload” and “config_settings.”

Not only did this make the code easier to understand, but it also felt like giving each variable a cool superhero name. Because they deserve it.

💡 Commit Message:

refactor: improve variable naming for clarity and readability
Enter fullscreen mode Exit fullscreen mode

Step 3: Adding the Secret Ingredient 🧂: Logging

Once the code was tidy and everyone had a name, it was time for the secret ingredient: logging. Now, whenever the program does something interesting (like processing files or calling an API), it leaves a trail.

If something went wrong, I could just check the logs and figure out exactly who messed up the party. It’s like having security cameras everywhere—super handy!

💡 Commit Message:

refactor: add logging for better debugging and tracking
Enter fullscreen mode Exit fullscreen mode

Rewriting History: The Magic of Git Rebase

Now came the fun part: squashing all those little commits into one clean masterpiece. With a bit of Git magic (and git rebase -i HEAD~3), I turned my three commits into one, like a chef perfecting their signature dish.

This way, my commit history looks like I knew what I was doing the whole time (even though I totally didn’t).

Here’s what my final, fancy commit looked like:

💡 Final Commit Message:

refactor: improve code structure, modularity, and readability

- Separated command-line parsing from AI logic and output
- Improved variable naming for better readability
- Enhanced error handling (or added logging) for improved robustness
Enter fullscreen mode Exit fullscreen mode

Dropping the Unwanted Guests

Oh, and let’s not forget—there were a couple of commits that I didn’t want hanging around at the party. So, I politely removed them during the rebase. No hard feelings, commits. You just didn’t make the cut.

The End Result: A Cleaner, Happier Codebase

After all the refactoring, renaming, logging, and squashing, I ended up with a much cleaner and more maintainable codebase. It’s like that feeling you get after tidying up your room—you can finally breathe and find your stuff again.

Lab 5 taught me that refactoring isn’t just about cleaning up code; it’s about making life easier for future me (and anyone else who has to work with the code). Plus, there’s something oddly satisfying about taking messy code and making it shine.


By the end of this lab, I was practically a refactoring wizard, armed with Git rebase skills and logging powers. Now, onward to the next challenge!

. . . . . . . .
Terabox Video Player