Code duplication, also sometimes known as code cloning, is a programming practice consisting in repeating the same (or similar) sequences of code statements within a software same project. Disadvantages of c.d.: bug propagation, increased code complexity, code clutter. Advantages of c.d.: reduced development effort, increased reliability (sometimes). Automatic c.d. detection tools exist including, e.g., Simian, Dude, CCFinder, Clone DR.
Questions tagged [code-duplication]
711 questions
-1
votes
1 answer
Elegant way to avoid duplicate code for looping through different depths of a nested dictionary?
I have a nested dictionary data of depth 3. So data[key1] is a dictionary, data[key1][key2] is also a dictionary and data[key1][key2][key3] is numerical.
I need to loop through different depths and at the moment I do that with several functions that…

Julien
- 13,986
- 5
- 29
- 53
-1
votes
3 answers
Refactoring and avoiding code duplication
I've ran into a problem that is new for me. Basically, someone else has already written a class A. The important parts looks like this
class A{
// some instance variables
public A(){
// Calls methods
build();
// Calls more methods
}
…

hokosha
- 305
- 2
- 4
- 11
-1
votes
2 answers
showing some view in all activities without duplication of code in Android
I have a condition when a specific event will occur in background, I have to show a Floating Action Button in bottom of activity to notify the user if App in fore ground. No matter in what activity the user is, if that event trigger by a service,…

Mahendra Chhimwal
- 1,810
- 5
- 21
- 33
-1
votes
2 answers
Java OOD and code duplication
I started creating a basic roleplaying game, and now I work on the basics. I have a code duplication for creating new characters and for existed character, which is a very bad things. I'll explain my problem - At the beginning a player can choose a…

Niminim
- 668
- 1
- 7
- 16
-1
votes
1 answer
How to keep formula duplicating when a new line is created in google spreadhseet
I am trying to automatically copy formulas into a range of cell but whenever I try adding a new line it deletes the formula and I have to copy it again. I am trying to eliminate this. Is there a script that will allow this or anything similar?
Here…

aku181
- 17
- 1
- 3
-1
votes
2 answers
How to avoid duplicated code, field vs local variable
I have a class that, in some scenarios, updates it's internal state permanently, and in other scenarios, calculates a projected value. The process of updating the internal state is the same as the process of calculating the projected value, but…

durron597
- 31,968
- 17
- 99
- 158
-1
votes
2 answers
Avoiding duplication in generating an id
The method generateId allocate ids to students,the method storeStudent is called by the method readData which reads data, the StudentId field in the data are all set to unknown so the method storeStudent replace the word unknown by a unique a id for…

Libya Ghassar
- 1
- 3
-2
votes
2 answers
Regex Replace c#
string formattedFormula = Regex.Replace("A1+A1", "(?!A1\\d+)[A1]" , "{" + 0 + "}");
I need the result as {0}+{0}. But this code replaced like this {0}{0}+{0}{0}
this is just an example.
using System;
using System.Text.RegularExpressions;
public…

Dev006
- 87
- 1
- 13
-2
votes
1 answer
What can I do to remove or minimize this code duplication that will provide the same functionality and behavior?
I have a set of derived classes and I'm using a function to update their internal ID values automatically upon class instantiation or creation. Originally I had this function in their base or superclass and it was working giving me correct results.…

Francis Cugler
- 7,788
- 2
- 28
- 59
-2
votes
1 answer
how to eliminate duplicate code in initmethod
I have classes Dog, Cat, ... extends of Pet and init method. How to eliminate duplicate code, if init method must be void.
public class Tester {
private Pet pet1;
private Pet pet2;
private int i;
public void pet1Init(){
…

Vadim
- 557
- 8
- 21
-2
votes
1 answer
Avoid duplicating While-Wend loop in excel vba
I have a very huge while wend loop in my Excel VBA.
Earlier in the code I set a variable strMode to True or False.
If it is False then in my while condition I want to set
while var1 + var1previous > 1
and if it is True
while var1 + var1previous >…

H_Tens
- 1
- 2
-2
votes
3 answers
Do the same action at the end of the try block and all catch clocks in a try-catch statement
Is it a way to avoid code duplication (FinalAction function call in all catch blocks and in a try one)?
try
{
// some actions including creation of new objects
FinalAction();
}
catch (const Exception1& ex1)
{
ProcessException1(ex1);
…

Constructor
- 7,273
- 2
- 24
- 66
-2
votes
1 answer
Duplicate error-noob programmer
Here's my code, I have no idea what is wrong with it I am completely new at this and I would appreciate it a lot if I can receive some feedback thanks:)When I try to launch my app in the emulator it tells me I can't because of theses…

Kamran
- 1
-2
votes
1 answer
no duplicates in random "case" list
I'm a total beginner and have almost no knowledge in programming, but i'm helping my 11 year-old son in creating a small quiz app, and we have a big problem as we can not make the questions in each category not to repeat before all the questions…

user3762849
- 3
- 2
-3
votes
1 answer
Two classes with duplicates
I'm new to Java and object oriented programming. I've tried to find the solution myself, but couldn't manage to solve this problem.
I have two duplicated pieces of code which I need to remove. As I understand it, I have to create a super class for…

dgr379
- 353
- 3
- 13