Cleaner Code as a Solo Dev

· [Daniel Baker]

Lately I’ve been trying to refresh my CPP skills by building a game. Part of the problem that I’m having is it’s been a good 10 years since I worked in CPP and a lot has changed since then. When I first started the game I was using raw pointers. I quickly switched to smart pointers but there’s still some aspects of the code using raw pointers. That’s just one example where I started a bad habit without realising it, and I’m still paying the price. The problem is when you’re learning a new language solo you don’t always know when you’re writing dirty code, since you have no one reviewing it.

In this post I’m going to talk about a couple of techniques I’m using to help make the code base cleaner.

My first tip is to install the pluign SonarLint. This little plugin is free. It acts as a Just In Time code review. Highlighting snippets of code where you may be introducing a code smell. The best part of this plugin though is not the highlighting, it’s the fact it explains why the code you’re writing will be harder to maintain, and then shows you alternate ways or functions you could be using instead. This is a fantastic resource for learning a new language.

Next up is doxygen. This can be used with a few languages but in CPP I’ve been using it to document my classes and their structure. Doxygen has a neat feature that allows you to render UML diagrams of your code. This is useful because it allows you to see where your code is getting too complex, giving you insights into how you can break it down. On top of that you can even have it recoginise ~TODO: ~ comments and generate documentation for them too.

Finally I’ve been using PlantUML and hpp2platnuml to generate UML diagrams that I can edit. This allows me to take a snapshot of the code base and then play with the UML to refactor some things. It allows me to move classes and methods around to see what kind of impact that will have on the code base. This is a really powerful way to start breaking up dependencies in a visual way.

Those are a few of the tools I’ve been using to help keep my code base clean. I hope you find them useful!