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
4answers
335 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 ...
1
vote
1answer
241 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
109 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
121 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
331 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 ...
2
votes
7answers
317 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 ...
0
votes
1answer
109 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
175 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
45 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: ...
2
votes
2answers
116 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
86 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 ...
0
votes
0answers
33 views

Duplicate code in DCI model and use case

I'm just coming in to an application that's already built with a DCI architecture. I've discovered in trying to implement a feature that there is duplicate code in a use case and a model. This is not ...
1
vote
3answers
140 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 ...
6
votes
2answers
408 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, ...
8
votes
3answers
376 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
364 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
124 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 ...
2
votes
2answers
181 views

How to avoid code duplication across unrelated projects [duplicate]

I'm a contractor at a large Telco where I'm usually working on several different projects at once. The VCSs I use (mainly git and mercurial) tend to make me keep the code bases for unrelated ...
6
votes
1answer
313 views

Reasoning to wait until third time in the Rule of Three?

I just came across the article "Rule of Three" in wikipedia Rule of three is a code refactoring rule of thumb to decide when a replicated piece of code should be replaced by a new procedure. It ...
82
votes
12answers
4k views

Best practices for sharing tiny snippets of code across projects

I always try to follow the DRY principle strictly at work; every time I've repeated code out of laziness it bites back later when I need to maintain that code in two places. But often I write small ...
4
votes
2answers
322 views

Better OOP in Javascript - multiple methods or methods with options?

Let's say I have an object like this: function Foo() { this.parser = new DataParser(); }; Within Foo I have a method that does something like this: Foo.prototype.getResponse = function(message, ...
1
vote
6answers
1k views

Validation of the input parameter in caller: code duplication?

Where is the best place to validate input parameters of function: in caller or in function itself? As I would like to improve my coding style, I try to find the best practices or some rules for this ...
25
votes
5answers
1k views

Many small classes vs. logical (but) intricate inheritance

I'm wondering what is better in terms of good OOP desing, clean code, flexibility and avoiding code smells in the future. Image situation, where you have a lot of very similar objects you need to ...
14
votes
3answers
655 views

Does decoupling trump DRY in REST?

I am building a REST API to expose most of functionality of an existing Java API. Both APIs are for internal use within my organization; I do not have to design for external use. I have influence ...
5
votes
4answers
559 views

DRY, string, and unit testing

I have a recurring question when writing unit tests for code that involves constant string values. Let's take an example of a method/function that does some processing and returns a string containing ...
11
votes
5answers
682 views

For an ORM supporting data validation, should constraints be enforced in the database as well?

I have always applied constraints at the database level in addition to my (ActiveRecord) models. But I've been wondering if this is really required? A little background I recently had to unit test a ...
9
votes
6answers
810 views

Interpretation of DRY principle

Right now I'm struggling with this concept of DRY (Don't Repeat Yourself) in my coding. I'm creating this function in which I'm fearing it's becoming too complex but I'm trying to follow the DRY ...
2
votes
1answer
272 views

How to handle repetitive code dealing with object properties?

Every so often I run into a situation where I need to map a set of properties from one object to another object of a different, unrelated class. The set of properties is large enough to make typing ...
8
votes
3answers
295 views

Is there a drawback in defining multiple small DRY classes, instead of bigger more repetitive classes? [duplicate]

I read some articles and it seems that using multiple classes in CSS is encouraged. I am curious to find out if there is a maximum number of classes an element can have before this multiple class ...
2
votes
1answer
396 views

WPF more dynamic views and DataAnnotations

Comparing WPF and Asp.Net Razor/HtmlHelper I find WPF/Xaml to be somewhat lacking in creating views. With HtmlHelpers you could define in one place how you wan't to represent specific type of data ...
19
votes
8answers
1k views

Adding complexity to remove duplicate code

I have several classes that all inherit from a generic base class. The base class contains a collection of several objects of type T. Each child class needs to be able to calculate interpolated ...
3
votes
3answers
160 views

How to apply DRY to files shared by repositories?

I've got a few files which are used in several of my repos: functions.sh, shell library to for example print a colored warning/error message or the documentation of a script file. Makefile; a ...
7
votes
2answers
433 views

DRY way to write Javadoc on overload methods

I want to write Javadoc in DRY way. But the oracle document about Javadoc says write same thing again in overload method comment. Can't I avoid repetition?
1
vote
3answers
2k views

Best practice for using a user control across many projects

I have a messaging User Control, that is used across 4 projects, and for each change I have to propagate it in 4 places. This is obviously against the DRY principle. However, centralizing user ...
5
votes
5answers
395 views

How do you keep SOA DRY?

In our organization, we've shifted to a more "service oriented architecture". To give an example, let's assume we need to retrieve a "Quote" object. This quote has a shipper, a consignee, phone ...
5
votes
3answers
236 views

Eliminating Dependencies vs Eliminating Redundancy

Upon my assignment to a project, I discovered that many message classes were received and then kept intact and passed around inside the receiving application. When these messages changed, code ...
1
vote
2answers
624 views

Hate repetition to the extreme [closed]

I program in a style that everything it's expensive or I really do hate repeating anything, mostly because I develop for embedded systems. So I get very annoyed when I have to do something that causes ...
10
votes
5answers
634 views

Violation of the DRY Principle

I am sure there's a name for this anti-pattern somewhere; however I am not familiar enough with the anti-pattern literature to know it. Consider the following scenario: or0 is a member function in a ...
7
votes
2answers
1k views

How to remove duplicate code (in general)?

In an OO language (e.g. but not limited to Java) how do you fix duplicate code depending on the scope of it's occurrence? I would start with (for example) in the same class (scope) perform the ...
2
votes
5answers
785 views

Is wrapping third-party API calls a design smell?

Five methods within my API call the same third-party method. In trying to abide by DRY, does it make sense to wrap this call in a private method?
4
votes
2answers
586 views

DRY with Dynamic SQL vs. prepared statements

When dealing with data, one finds that, essentially, the same code is repeated in various incarnations: -- MySQL: CREATE TABLE users ( id int NOT NULL auto_increment PRIMARY KEY, name ...
19
votes
8answers
2k views

How to implement DRY principle when using 'using' keyword?

Consider these methods: public List<Employee> GetAllEmployees() { using (Entities entities = new Entities()) { return entities.Employees.ToList(); } } public ...
61
votes
13answers
3k views

Why is DRY important?

Quite simple, why would I want to write code that works for all cases and scalable data when all I need to do is repeat the same process a few times with a few minor tweaks? I'm unlikely to need to ...
6
votes
2answers
2k views

Ruby on Rails and DRY

I've started to learn a little ROR and everthing I read says that ROR espouses the DRY principle and they seem to imply that this is a big thing that makes ROR different from other ...
10
votes
5answers
479 views

Is an architecture description document a violation of the DRY Principle?

The DRY Principle (Don't Repeat Yourself) states that "every piece of knowledge must have a single, unambiguous, authoritative representation within a system." Most of the time this refers to code, ...