detection of duplicated expressions

Posted on January 15, 2006

0


This week I’ve been looking at tools for detecting code duplication – specifically Simian and CPD. I didn’t try CPD in the end, because although it supports Ruby, CPD is bundled with PMD, which doesn’t. I did try Simian, and was impressed by the results. (I’m sure I would have been even more impressed if the alleged Eclipse plugin was still available.)

But I’m still searching for the tool I really wanted: something that can detect duplicated expressions. For example, here’s part of a class from William Wake’s Refactoring Workbook (ch14):

public class Game {
public int move(char player) {
for (int i = 0; i
The expression board.charAt(i) == '-' occurs five times (three of them negated), and yet I know of no tool that will report this. That's because the tools I've found all compare complete lines. And when I set their match size to one line I get matches for every 'end' and '}' etc.

So if you know of a tool that can detect duplication of expressions, please get in touch.

Posted in: duplication, simian