All Questions
Tagged with code-duplication dry
23 questions
3
votes
3
answers
287
views
How to avoid duplicate code with a helper-method for shared REST-operations like GET and DELETE
I have two methods
methodOne (e.g. for a GET on questionaire)
methodTwo (e.g. for a DELETE on questionaire)
Both have almost same lines of code.
IntelliJ also underlines the code and shows a warning:...
0
votes
0
answers
32
views
Is Organising Test Suite in inheritance hierarchy for DRY a bad thing? What alternatives are there?
I develop a system which:
accepts http requests with sometimes complex json arguments
sanitizes the arguments
loads data from database
checks conditions based on both
sends execution requests to ...
0
votes
1
answer
67
views
Java join duplicate methods
I have two methods in service that are mostly the same, except for the entity and runnable type.
Is there a way to join them?
I think generics could be helpful but have no idea how to apply them here
...
0
votes
1
answer
268
views
How can I repeat XML code while keeping it DRY?
I want to keep my code DRY for efficiency and maintenance. I write A LOT of XML for my programs and I was wondering how I can repeat code in the same file or from different files and directories ...
50
votes
2
answers
7k
views
How to reduce code duplication when dealing with recursive sum types
I am currently working on a simple interpreter for a programming language and I have a data type like this:
data Expr
= Variable String
| Number Int
| Add [Expr]
| Sub Expr Expr
And I have ...
1
vote
0
answers
155
views
refactor try-catch across class hierarchy
Suppose you have this code:
class Base {
void method() throws Exception {
try {
//Lots of code here
} catch (Exception e) {
//handle it (very little code ...
1
vote
0
answers
122
views
Don't repeat yourself or be more clear by repeating yourself?
I have this base class below:
abstract class RequiredString {
protected readonly string _text;
public RequiredString(string name, string text)
{
if (string.IsNullOrWhiteSpace(...
3
votes
1
answer
160
views
How do I remove code duplication between similar ref-qualified member functions?
Similarly to How do I remove code duplication between similar const and non-const member functions?, I want to remove the code duplication between nearly identical member functions, except for ref ...
0
votes
3
answers
103
views
How to avoid repeating work in Python without pass by reference?
I am writing web endpoints that take a JSON Web Token (JWT) and have to check the signature on the token. Since I am going to check the signature every time it makes the most sense to me that I should ...
2
votes
0
answers
76
views
Rails 4 CSV Generation of Index View without Code Duplication
How can I export my namespaced/resouce/index.html.erb content, which uses a partial for each row on the index page, into a CSV file, without duplicating code in the viewfile for the CSV (or in ...
1
vote
1
answer
130
views
Avoiding duplicate code while handling exception
For my application, I need to use two slightly different algorithms for persisting an entity:
def persistRandomAlias(self, alias):
self.em.persist(alias)
try:
self.em.flush()
...
0
votes
2
answers
641
views
In Ruby on Rails rake task is calling a function from another rake file
As you can see, I've defined a function inside a rake file. No problem, that works fine. Problem is, when I declare def get_user_input in another rake file. In that case the function gets called from ...
2
votes
1
answer
404
views
What language mechanisms does Lilypond have for simple abbreviations, to avoid code duplication?
In lilypond, I often find myself writing things like this
\version "2.14.2"
{
r2 c2 | gis'8 gis gis gis gis gis gis gis |
}
or this
\version "2.14.2"
{
\time 3/4 \clef bass \relative es,
{
...
3
votes
3
answers
1k
views
How do I avoid duplicating validation logic between the domain and application layers?
Any given entity in my domain model has several invariants that need be enforced -- a project's name must be at least 5 characters, a certain product must exist to be associated with the project, the ...
1
vote
1
answer
217
views
Pattern to avoid coupling between controller actions of parent and child controllers
Assume you have a Question and an Answer models, and that new answers are submitted from the questions#show page (like StackoverFlow).
Unless the questions#show and the answers#create actions load ...
2
votes
1
answer
155
views
cakePHP duplicating a function or using an outer controller? (DRY issue)
I have 3 controllers, Tokens, Stores and Users.
Token is related to the two other models, for each token there is a owner-type and owner-id.
There is also a function in both User_controller and ...
0
votes
1
answer
162
views
Applying DRY principles to JavaScript, help me optimize this code?
While on the search for ways to optimize the quality of my code, I eventually came across the concept of DRY (Don't repeat yourself). I try to follow this as best I can but sometimes I get into ...
11
votes
3
answers
5k
views
Duplicate code detection: Tools you can use
I am looking out for a software that identifies duplicate/redundant Javascript code. I found one such tool named CloneDR, but don't know how good it is .
I was looking out for similar open source ...
1
vote
2
answers
204
views
Avoiding repetition with <label>
When I'm coding a form I find myself doing some very repetitive typing. For example, if I'm lining up a number of <input>s in a table, I might write
<tr>
<td><label for="...
2
votes
2
answers
209
views
Avoiding code duplication in Delphi
I have two components A and B. Component B derives from component A and shares most properties and procedures with it. Now I have a lengthy procedure like this:
procedure DoSomething;
begin
Form1....
55
votes
13
answers
24k
views
How much duplicated code do you tolerate? [closed]
In a recent code review I spotted a few lines of duplicated logic in a class (less than 15 lines). When I suggested that the author refactor the code, he argued that the code is simpler to understand ...
3
votes
6
answers
2k
views
What duplication detection threshold do you use? [closed]
We all agree that duplication is evil and should be avoid (Don't Repeat Yourself principle).
To ensure that, static analysis code should be used like Simian (Multi Language) or Clone Detective (...
155
votes
11
answers
36k
views
Is duplicated code more tolerable in unit tests?
I ruined several unit tests some time ago when I went through and refactored them to make them more DRY--the intent of each test was no longer clear. It seems there is a trade-off between tests' ...