Measuring codebase progress
Any long running code-base will have rough edges. It will have areas of the code that are harder to debug, more error prone, or areas where design or usability are less than ideal.
Rough edges are a natural thing that should be expected and not feared. Sure, we can attempt to prevent them, but you’ll never be 100% successful. Plus, focussing too much on prevention is likely to slow down the shipping of revenue-increasing features.
Instead, I think it’s better to identify the rough edges, and to improve them slowly and steadily over time. Heres how...
What Rough Edges?
The Server Density UI definitely has some rough edges. This isn’t something I’m embarrassed about; instead I prefer to be honest about these things so they can be addressed.
CSS: We have one CSS file that is over 5000 lines long. It hides plenty of dead CSS, and it is very difficult to work with. It also contains far too many uses of !important.
Backbone Views: Our old Backbone views tend to contain UI elements that aren’t usability tested, are less composable and less performant than their React counterparts. In our codebase, Backbone views tend to not have unit tests, whereas our React components always do.
Backbone Models: Transitioning to Redux means we are in a phase where we have redux code that duplicates Backbone Models/Collections. Fixing this duplication would lead to less loading states as data fetched for one page is easily shared with another page.
Improving the situation
If we recognise these rough edges (and we should) we should start to think about what to do about them. How do we know it’s a rough edge? How do we know if it’s getting better? How do we measure it?
If it’s measurable we can track it over time, but how? At Server Density we use simple scripts like measure React component re-use to track 4 areas of the codebase every month:
Asset file size: This is more about how much duplicate or dead code we managed to remove. Byte counting is not that useful but removing dead or duplicate code is.
CSS health: Our new CSS is composed of little files where each file has 1:1 mapping to a component and a very specific namespace. Our old CSS is a very large file, a lot of which can probably be deleted. Plus, our old CSS uses !important too much and has weak namespaces or selector depth that is too deep.
Component reuse: This is about how generic and re-usable our components are, which is about productivity and UI consistency. This read-me is a good overview.
Backbone views: How successful we are at removing Backbone views in favour of more usable, more consistent, better tested, more composable React components.
Every month we measure these stats and add them to a spreadsheet, which allows us to compare where we are this month vs last month.
Does this work?
Sometimes it’s easy to see a benefit. Prior to monthly stats the CSS file-size was increasing, but now it’s decreased every month for 10 months by 27% overall. The important point here is the amount of dead or undesirable code that has been removed or replaced and how much easier the CSS is to work with now.
Tracking JavaScript file-size has also been positive. After 10 months of monitoring, the file-size is roughly the same. Pretty good considering we ship code almost every day, and have released major features like alert costs in that time. Again, the file size is not the important point, it’s the increased composability and the removal of dead code that this indicates which is important.
Other times it’s harder to say. Component composability has increased, and anecdotally this has improved productivity because new features have comprised mostly of pre-existing code. However, I can’t say if this would have happened without the stats. I also think focussing too much on further increases would make the codebase too tightly woven.
The danger inherent in focusing too much on instances per component reveals some interesting take aways from monitoring stats like these:
Stats should be a way to tell the story of a code-base, and should not be the end goal.
Stats should be taken with a pinch of salt.
The stats you monitor might have to change as a code-base changes.
Stats need to be really specific to the codebase. Stats that are valuable for one codebase might not be valuable for another.
That being said monitoring stats has been positive for us. I’m a big believer that they affect all the micro decisions you make because you’re much more likely to put in the extra work if you know it’s monitored. It’s a chance for reflection, and a chance to foster a team culture of making things better. It’s also something to celebrate every month, and those monthly celebrations add up to a serious amount of progress over time; progress that is addictive.













