DRY is short for "Don’t Repeat Yourself". This paradigm advocates to avoid code and data redundancy.
2
votes
0answers
41 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, ...
6
votes
3answers
271 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 ...
8
votes
3answers
271 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
90 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 ...
1
vote
2answers
138 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
224 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
...
74
votes
12answers
3k 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
178 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
495 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
479 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
384 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
595 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
604 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
209 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
283 views
Is there a drawback in defining multiple small DRY classes, instead of bigger more repetitive classes?
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
323 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 ...
18
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
152 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
335 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
1k 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
359 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
208 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
603 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
575 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 ...
6
votes
2answers
810 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
707 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
482 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 ...
5
votes
2answers
1k 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
437 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, ...