35

I'm looking for a code duplication tool that is language agnostic. It's easy to find language specific code duplication tools (for Java, C, PHP, ...), but I'd like to run some code duplication analysis on a templates in a custom syntax.

I don't care about advanced parsing of the syntax, just straight line based raw string comparison is fine. Whitespace insensitive matching would be a plus, but not required. (It's not that hard to normalize/eliminate whitespace myself.)

Does anybody know a tool that can be (mis)used for something like this?

ouflak
  • 2,458
  • 10
  • 44
  • 49
Stefaan
  • 4,696
  • 3
  • 23
  • 16
  • You get poorer clone detection if the detector knows nothing about the language syntax. Most clones aren't identical text; they are copy-paste-*edited* text, so to find them accurately you need to match *similar* but not identical code fragments. There are syntax-aware clone detectors, and to lesser or greater degree, they can be configured to know the precise langauge syntax. – Ira Baxter Nov 17 '12 at 19:19
  • possible duplicate of [Tips to show similarities in files](http://stackoverflow.com/questions/1536643/tips-to-show-similarities-in-files) – Ciro Santilli OurBigBook.com Aug 31 '14 at 13:15
  • I really think you'll do best focusing on logic duplication rather than raw string duplication. Some languages may be boiler-platey but that kind of duplication doesn't duplicate bugs. It's when you have the same, non-trivial logic in two places of the system that causes an unnecessary maintenance burden. –  May 06 '15 at 20:08

3 Answers3

21

Have a look Simian, you can use it for Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy source code and even plain text files.

Also, a similar question here.

Community
  • 1
  • 1
Doon
  • 3,339
  • 5
  • 25
  • 31
5

You can also take a look at Sonar http://www.sonarsource.org/

Catalin STAICU
  • 546
  • 1
  • 4
  • 19
  • 10
    Which feature of sonar cube could be used to find code duplication ? Could you please point us to it ? – MasterJoe Mar 18 '19 at 22:53
1

Take a look at this one https://siderlabs.com/

At this moment it support C, C++, Cuda and others Python, PHP, Java, Javascript coming soon

Shajibur Rahman
  • 436
  • 3
  • 12