Ask HN: Measurements of Code Quality?

3 points by timfsu ↗ HN
Hi HN community! A friend of mine recently inherited a large Javascript codebase that’s not in great shape. We were brainstorming ways to measure “progress” towards cleaning it up to help others understand what’s going on - some ideas include P90 file & function length, looking at import statements to determine the spaghetti-factor, and looking at the frequency of repeated chunks of code and general low effort code (poor variable names, n^2 loops, etc). We tried a few static analysis tools out there and didn't find the thousands of "errors" they detected very helpful.

I’m curious how you intuitively judge the goodness of code, and whether that could be measured. Let me know if you’d like to see this as an open-source tool too, though the last thing I would want is yet another way to “measure developer productivity”.

3 comments

[ 3.3 ms ] story [ 13.9 ms ] thread
Get a copy of "Your code as a crime scene", then check out two GitHub repos

https://github.com/adamtornhill/code-maat

https://github.com/smontanari/code-forensics

Thanks! We considered looking at Git history - churn is an metric that I've seen in other tools, but I don't have a great intuition for whether it's actually valuable. I just ran code-maat on the codebase I've been working on, and I'm not sure if it's that useful.

Our most touched files are our typedefs, package.json, backend routes, feature flags file, and the sidebar navigation component. These are large files that could be refactored, but I imagine I could've found those just by looking at lines of code. I'm curious if you have any stories of this being helpful?

Metrics like churn really need further processing to be most useful. One reason I linked code-forensics tool is that it produces deeper analytics and visualizations. For example, a diagram that shows both how large/complex a file is and how much it's changed is more useful. Another useful report from code-forensics is the knowledge map, which helps gauge ownership by analyzing the number of changes to each file by developer.

None these metrics and analysis will give answers, they are raw data to be used as input to thinking about organizational and design issues.