DRY is short for "Don’t Repeat Yourself". This paradigm advocates to avoid code and data redundancy.

learn more… | top users | synonyms (1)

1
vote
3answers
103 views

How can one think of a relational schema in terms of storing it in a NoSQL database?

Recently I've been wanting to experiment with NoSQL databases, especially document store ones. After reading, I still don't understand how one might model information that is contained in a relational ...
2
votes
1answer
41 views

WebForms, JQuery and the DRY principle

I'm working on a WebForms application that has several pages. Each page currently loads JQuery in a script tag in the head. A colleague I'm working with insists this is WET code and a violation of ...
3
votes
2answers
240 views

How to stay DRY with return values

I have a bunch of repetitive C++ code that looks like this: // Compute finalOutput if possible. Return true if successful, false otherwise // finalOutput only holds a valid value if true is returned. ...
2
votes
2answers
420 views

What did the reviewer refer to in this code review?

I sent the code for a job application and got the following review: Regarding the Project Structure: Physical separation is absent. Logical separation is present but not up to best practices. Things ...
1
vote
1answer
47 views

How to avoid repetition in docstrings?

I find that in my code, many methods in a class or a set of related classes have quite similar arguments: Arguments: dt_start (datetime): Starting date. Needs to meet complex requirements x and y ...
1
vote
3answers
306 views

How can I sell DRY? [closed]

Where I work we have around 10 VS projects in a solution which are identical in functionality (with some different different rules in a few methods) and share many exact methods. They share the same ...
1
vote
1answer
52 views

Tab management code in single-page applications acceptable violations of the DRY principle?

I have an AngularJS-based single-page app that allows the user to operate multiple items at the same time. I decided to use a multi-tab UI implemented in custom code. However, the user begin to ask ...
1
vote
4answers
351 views

What's the alternative to DRY code when it requires too many parameters?

What is the best strategy for maintaining easy to follow code when keeping things DRY means you have to pass a lot of parameters to shared functions? In my specific case, I have a grails based app, ...
1
vote
5answers
558 views

Is this taking DRY too far? [duplicate]

A colleague and I are working together on a Meteor app. One of us thinks that the following code in two places should be wrapped in a function to avoid duplication -- the other thinks that it leads ...
4
votes
4answers
162 views

Elegant way to handle multiple pathways based on compound condition [closed]

Consider the following: if (x == 5 || x == 10 || x == 12) { if (x == 5) { doSomething() } else if (x == 10) { doSomethingElse() } else { doSomeOtherThing() } ...
0
votes
3answers
207 views

call function once again after failure, without duplicate lines?

I have what is probably an over-engineering question. I have some PHP code that logs messages to a file. We've been having a problem with the file having the wrong perms from time to time. While we're ...
31
votes
1answer
4k views

DRY unrelated, but nearly identical, code

I have some code that is nearly identical, but uses absolutely different types, with no inheritance between them, on the main variable. Specifically, I am writing an analyzer with Roslyn for C# and ...
2
votes
1answer
76 views

Does declaring a field as final force redundancy in the constructors?

I have the following abbreviated class: public class Player { final private DoubleDuple position; final private DoubleDuple momentum; public Player() { position = new DoubleDuple(...
1
vote
1answer
285 views

Behat/Mink: best practice for testing strings in a web application's GUI

I'm writing acceptance tests for a web application using Behat/Mink. I want to know best practice for testing strings in the GUI. For example: say I want to test that a link exists on the homepage ...
8
votes
2answers
451 views

Const C++ DRY Strategies

For avoiding non-trivial C++ const related duplication, are there cases where const_cast would work but a private const function returning non-const wouldn't? In Scott Meyers' Effective C++ item 3, ...
7
votes
4answers
332 views

Can I make my constructors less repetitive?

I'm extending a class with 10 different constructors. The new subclass, SpecialImage, is used like this: SpecialImage specialImage = new SpecialImage(..); // Leverage the Rotate() method of ...
1
vote
3answers
770 views

Unit testing functions calling other tested functions [duplicate]

I have three functions: ValidateUsername(), which determines if a string is a valid username according to some rules SetUsername() which sets a string as a user's Username if it passes validation ...
-1
votes
2answers
107 views

Is it worth to rewrite the logic that already done client side on the server side or vice versa? [closed]

Few month ago, we created a logic to calculate customer progress in JavaScript. We didn't thought that it will be useful if we store them in our database. Now, i'm facing 2 options, Rewrite ...
0
votes
5answers
418 views

Should we always DRY? Any edge case examples of when not to? [closed]

I've only ever been working in higher level languages such as C# and JavaScript. A couple of moments ago someone asked this question on SO. Now I'm curious to know, for some of the lower level ...
0
votes
1answer
109 views

DRY principles vs local-only variable scope in functions (PHP motivated question)

I'm new to programming and in particular new to PHP. I often find that DRY is directly opposed to the principle of keeping variables local in PHP functions. Sometimes I think that it's easier to ...
2
votes
2answers
229 views

Unit testing and reusing extracted class

Currently I have 3 service classes, they all have a similar pattern, and I need to make a 4th service class which amalgamates the functionality of the other three. Current three classes public class ...
0
votes
4answers
304 views

2 methods that are 75% the same? [closed]

I have code that violates the DRY principle and I would like to consolidate 2 methods as much as I can, but the problem I am facing is that they have some differences, I would say they are about 75% ...
13
votes
7answers
2k views

How to sell DRY architecture [duplicate]

I'm sure most are familiar with the phrase DRY in the software world - Don't Repeat Yourself. This is a fundamental principle of good software development. Here is a question (background first). ...
3
votes
2answers
149 views

Separation of logic from presentation results in repetition of code

Here's what I've been thinking. Say you're making a multiplayer game. A good way to structure it is to have all your game logic on the server and have the clients only be responsible for transmitting ...
2
votes
2answers
145 views

Is it acceptable to refactor a collaborator's code?

When working with other people in a project, is it acceptable to refactor some of their code? I'm working with another developer and I notice a lot of duplicate code. To make things easier for myself,...
1
vote
2answers
147 views

Refactoring: reducing duplication without creating flags

I don't know how to refactor a piece of code that differs from other in the number of conditions checked on an if clause. Let me show you a real world example I'm facing right now. The only ...
3
votes
0answers
130 views

Should I inject a data dependency into an Angular Directive?

I am currently implementing an AngularJS directive. It is fundamentally a reusable widget comprised of a select box and a table which populates based on the item in the select box. My point of ...
19
votes
6answers
2k views

The importance of duplicate code removal [duplicate]

I tried to explain to a coworker the gravity of having duplicate code in a project, on this piece of code: + (void)createIapInParse:(SKPaymentTransaction *)transaction { Reachability *reach = [...
1
vote
2answers
246 views

Is goto to improve DRY-ness OK? [duplicate]

My code has many checks to detect errors in various cases (many conditions would result in the same error), inside a function returning an error struct. Instead of looking like this: err_struct ...
1
vote
1answer
109 views

How do you wrestle the DRY principle with configs?

For instance, lets say we have an nginx config pointing at foo1, foo2, and foo3, as well as a haproxy config pointing at foo1, foo2, and foo3, and finally, a deployment tool pointing at the same ...
1
vote
3answers
215 views

Redundant function to clarify purpose? [duplicate]

Since what matters is not how the code does it but what it does, would you consider wrapping a function with a different name just to clarify it's behavior in certain situations a good practice? ...
4
votes
2answers
147 views

Forking an application for an “enterprise” customer

Note: this is mostly a technical question but I have to explain the business background first. THE BUSINESS PART I have a really interesting situation on my hands, at least interesting for me. For ...
7
votes
4answers
2k views

Managing client-side and server-side validations in one place

I'm 100% on board with the case that one should definitely use both client-side and server-side data validations. However, in the frameworks and environments I've worked in, the approaches I've seen ...
3
votes
5answers
720 views

DRY code, DRY tests?

At some point I had to create some class "Class1" and that class needs a method "method". So I have the following: Class1MethodTest: A total of N tests that check the behavior of Class1.method Class1 ...
2
votes
1answer
766 views

Avoid code repetition in CRUD operations

I'm developing a PHP application and I find myself doing basically the same code for, say, creating an object based on a form filled by the user. The objects are of different classes, but the process ...
2
votes
2answers
248 views

Don't Repeat Yourself across integration-test code and production code?

I totally believe in not repeating yourself in production code. I've accepted the idea that you shouldn't repeat yourself within test code. But what happens when you have production services that ...
0
votes
0answers
172 views

DRY on API specifcations?

When developing a new RESTful application, I generally: Define tests Define routes [ e.g.: RESTful CRUD; namespaced on /api/users ] Define models [ e.g.: "Users" ] Define forms [ e.g.: in ...
1
vote
5answers
712 views

Should unit-tests be entirely self-contained? [duplicate]

As the title suggests my question is whether or not unit-tests should be entirely self-contained or can one rely on the results yielded by previous tests? What I mean, in case that it isn't entirely ...
8
votes
10answers
1k views

Testing vs Don't Repeat Yourself (DRY)

Why is repeating yourself by writing tests so highly encouraged? It seems that tests basically express the same thing as the code, and hence is a duplicate (in concept, not implementation) of the ...
1
vote
1answer
180 views

Handling array passed to object at creation

When creating my object I pass it an array of a row from my database. (everything in the array we will need, disregarding unnecessary elements at sql query level) When I need to access certain array ...
2
votes
2answers
325 views

Achieving multiple tasks within one loop

With relation to what's considered good OOP engineering principles, SOLID, DRY, KISS etc I am wondering whether to complete multiple tasks within one loop when easily done. The problem is that this ...
1
vote
1answer
62 views

Use a setStatus($arg) function or have separate enable() and disable() functions?

I've got two functions at the moment: suspendGroupsAndUsers($groupId){} enableGroupsAndUsers($groupId) {} But the difference between the two is one variable/string. Should I just have: ...
4
votes
3answers
860 views

How is DRY principle ( applied at class level ) related to SRP?

In other words, is DRY (don't repeat yourself) applied at a class level a subset of SRP (single responsibilty principle)? What I mean is that while SRP states that each class should have only a ...
3
votes
4answers
150 views

A metric to measure the cost of cut and paste programming

I'm hunting a metric to measure the cost of cut-and-paste programming. We already use tools to detect duplicated code - but if we don't clean up our duplicated code, how much will it cost us? We ...
2
votes
3answers
556 views

Repository query conditions, dependencies and DRY

To keep it simple, let's suppose an application which has Accounts and Users. Each account may have any number of users. There's also 3 consumers of UserRepository: An admin interface which may list ...
7
votes
2answers
920 views

Practices for domain models in Javascript (with frameworks)

This is a question I've to-and-fro'd with for a while, and searched for and found nothing on: what're the accepted practices surrounding duplicating domain models in Javascript for a web application, ...
0
votes
3answers
156 views

project with 2 types of interfaces performing different jobs, should they use the same BLL and DAL?

I am working on a project that has two interface (web and desktop), they are not performing the same tasks but they use the same BLL and DAL, the web part using 100% of the BLL and DAL, while the ...
10
votes
3answers
704 views

Doesn't single-assert unit testing break the DRY principle?

Whenever I write unit tests I have always tried to have a single assert per test to make debugging easier when tests fail. However as I follow this rule I feel like I am constantly copying the same ...
9
votes
3answers
2k views

I have to compromise: DRY, or Command-Query-Separation?

I was recently refactoring a method that was both a command and a query method. After separating it into a one command method and one query method, I found that there are now multiple places in the ...
3
votes
1answer
484 views

calling test methods within other test methods

To test a method that returns a clone of the object it is called on, i need to re-run the test suite on the newly created object if i am to ensure that full functionality is retained, i found my ...