Sadly, a project that I have been working on lately has a large amount of copy-and-paste code, even within single files. Are there any tools or techniques that can detect duplication or near-duplication within a single file? I have Beyond Compare 3 and it works well for comparing separate files, but I am at a loss for comparing single files.
Thanks in advance.
Edit:
Thanks for all the great tools! I'll definitely check them out.
This project is an ASP.NET/C# project, but I work with a variety of languages including Java; I'm interested in what tools are best (for any language) to remove duplication.
What is duplicate code? Duplicate code as the name suggests is a repetition of a line or a block of code in the same file or sometimes in the same local environment. People might consider code duplication acceptable but in reality, it poses greater problems to your software than what you may have thought.
I recommend keeping your duplication percentage to a minimum. Every company has it’s own threshold for duplication percentage which matches their quality standards. Having 0% duplication is very difficult and gets tougher as the number of files of source code increases.
Duplication decreases your code quality : Have duplication is fine, as long as you plan to throw your software away soon. Code quality is a necessity to make your software survive for long. Having duplicate code will make your code smelly and increases technical debt associated with it.
Having 0% duplication is very difficult and gets tougher as the number of files of source code increases. The most important thing is to follow proper coding standards like DRY and having an efficient code review process in place. It is important to conduct code reviews on a timely basis so as not to increase the technical debt later on.
Check out Atomiq. It finds code that is duplicate that is prime for extracting to one location.
http://www.getatomiq.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With