Reviewing / testing / refactoring code efficiently

Submitted by kofa on Thu, 11/10/2011 - 21:26

Updated: you should check out this 40-minute presentation. The stuff below covers just one of his recommendations: testing code that changes often, in case your VCS is SVN.

Reviews and refactoring take time - and there's just never enough of that. Once I found a blog entry (sorry, I can't seem to find it now - but Google's recent observations are similar) that said if you're working on a large codebase that has evolved for a long time, and you want to make improvements, you should concentrate your limited resources on code that actually changes. The rationale is that code that has worked well for a long time is probably stable - even if you don't want to touch it with a ten-foot pole.

If you use SVN, you can get the most frequently updated code like this (I'm assuming you are on 'trunk' and are only interested in java source files):

prompt> svn log -r {yyyy-MM-dd}:nnnn -v | gawk '/java/ {arr[$2]++} END {for (i in arr) {print arr[i], i}}' | sort -nr >sorted_commits.log

Here yyyy-MM-dd is the date of the least recent modification that will be included, nnnn is the current revision number; gawk is the GNU version of awk, sort is the GNU version of sort. (Windows users, beware: you'll need double quotes (") instead of single (') for awk; also, Windows' sort utility will probably precede GNU sort on the path.)

This will give you a list, sorted by number of commits involving each file, in descending order (most frequently updated file on top).

Happy reviewing!