All Questions
Tagged with code-duplication methods
15 questions
0
votes
1
answer
217
views
How to generalize methods using functional Java
Can we reduce code duplication with these methods with the new java functional paradigm? I tried to pass the function as param. But one has Functional and the other BiFunctional. Unable to make it as ...
1
vote
2
answers
2k
views
How do I prevent code duplication when defining multiple methods with the same name?
I recently discovered that you can define multiple methods with the same name as long as their arguments differ (I believe it's called method overloading). So for example, in a script I have a method ...
3
votes
4
answers
3k
views
Refactoring functions with nearly entirely duplicate code but different calls to other methods
I'm learning Java and I'm in the middle of online courses and such, and I'm on one of the coding exercises and realized there is a whole lot of duplication between my two methods, found below:
...
0
votes
1
answer
754
views
How to find duplicated Ruby methods with the same name but different code?
The very large Ruby codebase I am working with has many instances of duplicated methods defined with the same name but some of its code is different (causing a large race condition problem). The ...
1
vote
0
answers
132
views
When should I split up a method into more methods?
I have two similar methods for setting dimensions of a rectangle. At first, I had them combined into one longer method that set width and length. I read about keeping code modular that performs one ...
0
votes
0
answers
222
views
C# code extract FROM methods
Does someone know a c# tool that could extract all code in given class from methods?
Example starting file:
public class HelloWorld
{
public static void Main()
{
Print("Hello, ");
...
2
votes
2
answers
80
views
Code duplication in methods when a value needs to be different but not the method
I have a class that handles a properties file (in which the end user will OAuth2 consumer key and consumer secret values).
In this class I've got a method like this:
// Get the consumer key or ...
1
vote
1
answer
65
views
Java prevent method duplication for same purpose - different parameters
I have 2 methods that are almost identical. I'd like to know if there is a way to combine these 2 methods into 1, which would allow me to take both types of maps as a parameter. The methods writes ...
1
vote
2
answers
121
views
How to avoid code duplication with similar Django model methods?
The following model contains the two almost identical functions list_ancestors and list_descendants. What would be a good way to write this code only once?
class Node(models.Model):
name = models....
1
vote
1
answer
42
views
Method is outputting incorrect value? [closed]
So I'm working on an assignment that is trying to output the energy consumption of appliances within a house. I have created an Appliance called ElectricCooker and an Appliance called ElectricShower. ...
0
votes
1
answer
60
views
Keeping code DRY when repeatedly referring to command-line options' configuration
I just got a Raspberry Pi, and I'm building a Reddit API-based application for it, using the PRAW library. I'm executing my python files by using:
sudo python3 main.py
However, I would like to pass ...
1
vote
1
answer
288
views
Conditionally adding extra else if statements
The following is called from every level of my app (a game)
Pseudo code example
public void checkCollisions(){
if (someCondition)
do something
else if (someCondition2)
do ...
0
votes
1
answer
195
views
Refactoring code with the Extract method
In my application, we have a class which generates information within a database as static centralised data. This class is called 'GenerateOwner'. Within this class we are creating multiple entries of ...
3
votes
4
answers
5k
views
How to generalize a method call in Java (to avoid code duplication)
I have a process that needs to call a method and return its value. However, there are several different methods that this process may need to call, depending on the situation. If I could pass the ...
0
votes
4
answers
199
views
Efficient way to avoid duplicated code of buttons clicks
Say I have 2 buttons witch supposed to perform the same operation but on different objects.
Currently I'm passing all the needed references to the method like this:
private void ...