Dot Plots: A Coder's Towel

  • user warning: Table 'nolan.comments' doesn't exist query: SELECT COUNT(*) FROM comments WHERE nid = 309 AND status = 0 in /home/sneakin/web/nolan.eakins.net/includes/database.mysql.inc on line 120.
  • user warning: Table 'nolan.comments' doesn't exist query: SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread, c.status FROM comments c INNER JOIN users u ON c.uid = u.uid WHERE c.nid = 309 AND c.status = 0 GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, u.picture, c.homepage, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread, c.status ORDER BY c.thread DESC LIMIT 0, 50 in /home/sneakin/web/nolan.eakins.net/includes/database.mysql.inc on line 120.
|

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