views:

269

answers:

3

In a project, I found some css files that "smell" like there are copy-pasted rules in them.

I wonder what are your strategies for detecting copy-paste stuff in files.

Just of curiosity i'd like to hear your tips and tricks for showing file similarities!

+1  A: 

There is a Copy-Paste Detection (CPD) project on sourceforge; http://pmd.sourceforge.net/cpd.html

But even in large projects I find my own knowledge of the code to be a reliable (although not foolproof) detection mechanism.

Also see this question for other suggestions.

Ed Guiness
The CPD tool seems very limited in languages. And does not have javascript or CSS
Jesper Rønn-Jensen
Thanks for pointing to "this question". Very similar to this, btw :)
Jesper Rønn-Jensen
+1  A: 

Try Simian.

It is used for copy-paste-detection in source code (Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy), but you can run this on plain text files too.

The Chairman
is there a way to make simian show the actual similarities? On my test-run, it only shows a summary that "lines a to b in file X are similar to lines c to d in file Y"???Showing the actual lines will help clarify a lot
Jesper Rønn-Jensen
Or better yet: is there a way to make it show diffs for the lines that are similar?
Jesper Rønn-Jensen
I'm afraid you'll have to check the results manually or write a tool that evaluates Simian results and attaches them to a file viewer. Maybe you could utilize a free diff tool (e.g. WinMerge, http://winmerge.org/) for that purpose. If you decide for the latter: I would be interested in such a solution too...
The Chairman
See my answer on CloneDR for a tool that explicitly shows similarities and differences.
Ira Baxter
A: 

The Semantic Designs CloneDR is a tool that detects copy-paste-edit blocks of code, for many languages: C, C++, Java, C++, COBOL, ECMAScript, PHP, ...

It generates a report that shows exactly how the blocks of code are similar, and precisely how they vary. You can see sample reports at the link.

Ira Baxter
Your link is not working? Could you please update your response?
Jesper Rønn-Jensen
...oops... fixed.
Ira Baxter