Dot Plots: A Coder's Towel

|

I just slapped together a dot plotter after scanning through Object-Oriented Reengineering Patterns. That book describes the use of dot plots to detect duplicated code. While it's a bit like reading tea leaves, it is a good detector as the following two plots of dotplotter.rb against itself show with the huge run down the middle:

Dot Plot of dotplotter.rb against itself in Ruby mode (-r) Dot Plot of dotplotter.rb against itself in Line mode (-r)

The first is dotplotter.rb running with the "-r" option which compares tokens to tokens thus making each row/column a token such as "def". The second, smaller one is in line mode, "-l", which compares lines with lines. That makes each row/column an actual line in the source file.

The huge diagonal line through the middle indicates a huge run of duplicated code. That's because it's the same file against itself. Now if these were separate files, then the runs would hopefully not exist since any such run indicates duplication.

The dot plot script can be found at the following site. It requires RMagick and ParseTree to work: http://nolan.eakins.net/code/dotplotter.rb

AttachmentSize
dotplot2.png1.28 KB
dotplot1.png16.47 KB

Ad's by Google