Friday, September 12, 2008

Towelie Keeps Your Code DRY

This morning, at an internet cafe in rural California, near a beautiful little river, I finally got this idea into a working proof-of-concept form.

Towelie is a small Ruby library which can comb through a code base and identify method definitions which are exact duplicates of each other.

I got the idea from Stu Halloway, who talks at conferences about creating graphs with lines of code on one axis and flog scores on the other.

I think I saw Stu explain this at Ruby Nation, in mid-July. I've been hacking on Towelie on and off since then. ENTP just had a week-long camping retreat, during which WiFi was only sometimes available, and the extra hacking time allowed me to finally get Towelie into 0.0.1 territory. (I also hacked on it at Burning Man, although it was harder to find electricity for my laptop there.)

Currently all Towelie can do is identify two method definitions which are completely identical, in two small, simple files. A different fork of Towelie also counts repeated lines of code, minus obvious harmless repetitions such as end or empty newlines. Future versions of Towelie may or may not come into existence at some point in future, with niftier powers.

The GitHub repo is here.

Towelie is, of course, the worst character ever.

Update: When I first posted this, I had pushed the wrong branch to GitHub. That's fixed. I also hacked a few extra features on the plane: Towelie can extract unique methods, and methods which have the same name but are otherwise different.

Update: Towelie can make its comparisons across modules and classes now.