code-duplication

How best to handle duplicated code across platforms/tiers?

I'm curious about how everyone handles code duplication across multiple platforms/tiers. As an example, in our application we have a screen that displays claims. A claim is deemed to be outstanding if it satisfies certain critera and users want to see which claims are outstanding in their lists, so there is one piece of code in the appl...

Static code analysis tool to detect code duplication in Maven projects

After I found out that there's no plugin for Simian in Maven 2, we turned to CPD, but it doesn't perform as well as Simian (observed in our Ant projects that use both Simian and CPD). I know that developers in my team have been checking in redundant code but CPD isn't flagging anything. I wanted to try out another code duplication analys...

Any valid reason for code duplication?

I'm currently reviewing a very old C++ project and see lots of code duplication there. For example, there is a class with 5 MFC message handlers each holding 10 identical lines of code. Or there is a 5-line snippet for a very specific string transformation every here and there. Reducing code duplication is not a problem in these cases a...

Why I see so much code duplication in Linq in Reflector?

Hi! Edit: I made a mistake in my original question. It should be about methods Last and LastOrDefault (or Single and SingleOrDefault, or First and FirstOrDefault - plenty of them!). Inspired by this question, I opened Reflector and looked at code of Enumerable.Last<T>(this collection) Then I jumped to code of Enumerable.LastOrDefau...

How can I find copy/paste (duplicate, clone) code in Perl?

I've searched the Internet for a while now and I have not been able to find any free (or cheap) tools/utilities/modules that can analyze a set of Perl files (modules or scripts) and flag duplicate or cloned or copy/pasted code. I'm better now, but I used to copy and paste sections of code all over the place. I'd like to clean it up and...

What is the best way to find duplicate code?

What tools can I use to find duplicate code that is a good candiate for refactoring? Update: Any language, any IDE. ...

What's the best way to avoid code duplication in these two functions that do the same thing?

Given this form (which contains a submit button): <form id="review_form"> <input type="submit" id="btn_submit" value="Submit with ajax! (submit button)"> </form> and this link (to submit the same form): <a href="#" id="lnk_submit">Submit with ajax! (hyperlink)</a> In the following jQuery code, when the #btn_submit element is clic...

Is it better to have code duplication and have it be very simple/readable, or have no duplication (using generics) but be much more complicated?

In general I come across this a lot. Some of my co-workers prefer very simple, easy to read classes even if that means that there is some code duplication, whereas I do everything in my power to avoid code duplication, even if it means making more a complicated architecture. What is the best practice? I work exclusively in Java. ...

Visual Studio Web development - removing code duplication

Hello, I am developing a basic .html website using visual studio. I am wondering on how other people find this experience. I do not really want to replicate the navigation, header, footer code in each page so what do you use? I was thinking I might have to use master pages and aspx, unfortunately masterpages and .html do not go. In d...

I need a tool to find duplicates or similar blocks of text in a singular text file or set of text files.

I want to automate moving duplicate or similar C code into functions. This must work under Linux. ...

CPD / PMD between projects?

Hi all, I am rephrasing this question to make it a little more straightforward and easy to understand, hopefully. I have roughly 30 components (internal) that go into a single web application. That means 30 different projects with their own separate POM. I use inheritance quite a bit in my POMs so one of the things they inherit is a ...

How can I codegen classes like this in C#?

I have multiple classes in a project that are exactly the same except for the name of the class. Basically, they represent glorified enums loaded at runtime from config files. The classes look like this: public class ClassName : IEquatable<ClassName> { public ClassName(string description) { Description = description; } ...

Need help avoiding code duplication across multiple method signatures

I have a need to restrict certain numbers to valid ranges in my application. I created delegates to handle this. I don't know if this is the right way to do it; I'm running into something that feels wrong. public delegate int RestrictInteger(int minimum, int maximum, int value); public delegate decimal RestrictDecimal(decimal minumum, d...

any ideas for avoiding duplicate code in C# and javascript

i have an asp.net mvc website where i build up most of the page using C# for example building up html tables given a set of data from my viewmodel i also have a lot of javascript that then dynamcially modifies these tables (add row for example). the javascript code to add a new row looks extremely similar to my "rendering" code i have ...

Is it possible to add a reference to some source code to include in a source file in vb.net, winforms?

I don't know what this is called so I've struggled to find an answer from google but I have a vague memory of it from t'old days. I've sub-classed (* see below) about 8 framework controls, overriden some properties and added some functionality into each one. The changes I have made are identical in every case. If I make a change, I have...

How do you avoid code duplication when implementing const and non-const iterators?

I'm implementing a custom container with an STL-like interface. I have to provide a regular iterator and a const iterator. Most of the code for the two versions of the iterators is identical . How can I avoid this duplication? For example, my container class is Foo, and I'm implementating FooIterator and FooConstIterator. Both of th...

Eliminating code duplication in a single file

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 ...

Java Prevent code duplication when getting a list of a property in each Object from a list of Objects

I have several objects that look like this: class PhoneNumber { String getNumber(); String getExtension(); DateTime getLastCalled(); } class Address { String getCity(); string getState(); int getZip(); } I'd like to be able to take a List of any one of those objects and get a list of a particular property. Th...

Avoiding code duplication in F#

I have two snippets of code that tries to convert a float list to a Vector3 or Vector2 list. The idea is to take 2/3 elements at a time from the list and combine them as a vector. The end result is a sequence of vectors. let rec vec3Seq floatList = seq { match floatList with | x::y::z::tail -> yield V...

Any tools to check for duplicate VB.NET code?

I wish to get a quick feeling for how much “copy and paste” coding we have, there are many tools for C# / Java to check for this type of thing. Are there any such tools that work well with VB.NET? (I have seen what looks like lots of repeated code, but wish to get some number to help me make a case for sorting it out) Update on prog...