Code metrics, the only ‘right constant’
I wrote recently about the experience of running a code analysis tool on a codebase and hinted at the difficulties involved with refactoring the problems. There are far smarter people than me who have given much more thought to the technical problems and strategies involved. I want to explore, instead, the cultural and human problems involved.
I doubt there’s a developer who wrote the first line of code in a codebase without thinking, ‘this time I’m going to do it right.’ And I also doubt there are many developers who are working in a codebase who aren’t thinking, “If I get a chance to start from scratch, I’m going to do it right.” So how is it possible that these two sentiments exist simultaneously?
The answer is another paradox- early development is done without enough rigor and is done with too strict adherence to early established principles. Ie, the rigor that is used is applied towards principles that fail in the long run. Over several years, languages change, technologies become available or obsolete, developers grow and evolve, etc.- and the codebase becomes larger.
The way to ‘do it right,’ then, is to establish what is right as a constant and what is correct right now. In all of software development, the only thing that I can think of that is ‘right as a constant’ is code quality metrics- things that are not subjective (like code reviews), and backed up with empirical evidence about effects. If code quality metrics are not part of your process, your codebase is likely to fail. As a codebase grows, so does the liklihood that future development is under the paradigms already existing in the codebase. The problem is, these paradigms have no certainty that they will yield good code. In fact, chance is they will be directly at odds with more widely established and accepted principles and paradigms that have evolved or appeared after the codebase started. This is the nature of the myopia and bubble that forms at any sizeable development house.
The only way to fight this is to apply the steady force of the ‘right as a constant’ factors to a codebase. If you can do this, you’ll always be at a more agile place, so you can refactor more easily. Anecdotal evidence would indicate that any other strategy is futile.
Have I missed any other possible ‘right as a constant’ things that can be implemented?
Next up: What implications does this have for culture?
[…] Last time I went over how adhering to things like code quality metrics that are objective and ‘scientific’ is the key to creating and sustaining a strong codebase. The difficulty comes with actually implementing that process and behavior wherever you work. There is no shortage of obstacles: […]