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

learn more… | top users | synonyms

1
vote
2answers
108 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
196 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 ...
51
votes
7answers
2k 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 ...
3
votes
1answer
140 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
337 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
410 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
326 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 ...
10
votes
5answers
550 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
506 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
188 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 ...
2
votes
1answer
280 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 ...
17
votes
8answers
992 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
151 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
283 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
841 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 ...
4
votes
5answers
340 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
193 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
589 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
479 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 ...
2
votes
5answers
656 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
436 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 ...
18
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 ...