"Don't Repeat Yourself", or DRY, is a software development philosophy which aims at reducing redundancy and code repetition.

learn more… | top users | synonyms

6
votes
1answer
73 views

How to DRY up my forms.py?

I have two ModelForms that are the same, except that one of them has its form layout built in a view and one has a submit button. These are pretty long and I have a ...
3
votes
3answers
614 views

Any simpler and more efficient way of writing this code?

I've noticed I've got quite a few repeated lines in my code. ...
4
votes
2answers
78 views

Wait until all files are loaded asynchronously, then run code

I'm an experienced programmer but not too great at JavaScript so I'm looking to see if I'm doing this 'right'. I want to have several files loaded in (Ajax or really AJAJ) and, once loaded, run some ...
1
vote
1answer
48 views

Refactoring scoring algorithm

I have the following code which I feel that I must refactor, but not sure how to do it. ...
1
vote
0answers
13 views

How can I clean up this hack to scrape paths from a Gruntfile?

As a part of my Tabv Vim plugin (which at this stage is nothing more than a pitiful rag-tag assortment of half-baked hacks), I have a function which attempts to guess the directory paths for main ...
10
votes
5answers
860 views

DRY the throwing of ArgumentNullException(“ParameterName”)?

I am using this code in a lot of places: if (ParameterName == null) { throw new ArgumentNullException("ParameterName"); } But I think this is not DRY. The ...
5
votes
3answers
71 views

jQuery Tab function

I have this script that I need to run a tab (jquery). Mainly I need to hide some div and add class (you sure have understood). How should it be written in a more elegant and readable? ...
4
votes
2answers
49 views

How can I DRY up these routes?

I have a controller with just a few actions, not the whole 7 RESTful actions situation. Here's what I have so far for routing: ...
9
votes
1answer
79 views

Tabbed navigation to hide and show pages

I'm new to jQuery and trying to learn how to refactor my bloated code to make it nicer and better maintainable. I have a tabbed navigation which I'm using jQuery to hide and show pages depending on ...
5
votes
1answer
57 views

Shorter way of writing my displayError() function?

Is there a way I can write this function with less code? jQuery ...
2
votes
2answers
100 views

Is there a simpler, more efficient way to write this function?

I see that there are quite some words that are appearing double or more times in my code. So I'm thinking there might be a more efficient way of writing this code, only I don't have the knowledge to ...
2
votes
2answers
95 views

How to simplify these jQuery lines?

I want to find a way to make a function from my code. I'll have more than 20 queries like this. It's time to make a function. :) ...
6
votes
3answers
246 views

Next Instance of DRY Refactoring

I'd like some additional assistance on refactoring. This is my latest update for this iteration. ...
6
votes
3answers
210 views

Should I refactor for DRY?

I'd like to get some input on whether or not to DRY up this code. And if so how to implement it correctly. How do I know when it's worth refactoring? ...
4
votes
2answers
65 views

Do I need to trim this jQuery code?

I had three multi-select boxes from this page. I want to customize each box so I simply repeat the code three times with different options: Check the fiddle ...
4
votes
2answers
60 views

Is my simple string tokenizer wrapper orthogonal?

I always learn something from Code Review, so if anybody could point out any bad practices in design, violations of DRY, or orthogonality problems I would be extremely grateful! ...
5
votes
1answer
41 views

remove redundance in compare-functions

I wrote some compare-functions that I pass to other methods in javascript: ...
11
votes
9answers
2k views

Is there a more succinct way of writing this simple JavaScript loop?

This seems a bit redundant to me, but I'm not sure of how else I might be able to write this. Normally I'd use a switch statement, but I don't think that'll work ...
5
votes
2answers
133 views

Removing everything after a certain character

I was just writing code, and wanted to make a piece that removes everything after the character ? if it's found within the URL. ...
6
votes
2answers
440 views

How to dry up this code without meta programming?

I have a ruby code segment which I need to DRY up. Following is the code segment. ...
1
vote
1answer
36 views

DRYing Up RSpec

How would you DRY up this RSpec code? ...
2
votes
1answer
77 views

Delegate that selects a writable property on a generic

In the following contrived example, I have a collection of PropertyManagers that each contains selector and assigner delegates to read from and write to a property ...
4
votes
1answer
22 views

toggleSaveStream button template

I've got a view which has a corresponding template. The template looks something like like: ...
3
votes
1answer
44 views

Checking for a value on selectors

I've got some pretty simple validation that I'm working on, but it seems like I'm repeating myself a bunch of times. There has to be a better way of doing this. I'm simply checking if there is a value ...
3
votes
1answer
525 views

Better way to handle a sign up wizard in AngularJS?

I think my current structure is way too repetitive, I feel like I must be missing something that would easily make this sign up wizard work far better. First post on code review, I tried to follow the ...
1
vote
3answers
26 views

Is it possible to condense this code?

I have three functions, each assigned to an anchor tag which gets called onclick. Is there a way to condense this code? It seems redundant to have three function ...
5
votes
1answer
43 views

Is this HTML structure and CSS DRY enough in this country selection menu?

I have built this conceptual design of a localization menu on this CodePen I am wondering if I should have structured my <div>s better or if this should be ...
15
votes
5answers
982 views

Validating opening and closing bracket pairs

I have refactored one of my old homework assignments (mainly to utilize std::stack and some C++11), and I'm still having trouble making it less repetitive. It ...
3
votes
3answers
60 views

Reducing conditionals if a selector exists

I've got a conditional that sets a cookie based on if a selector exists. There are other places in the code where I do something similar if the selector exists. If the selector exists I either add ...
2
votes
1answer
78 views

Code reuse while keeping meaning clear and avoiding unforseen consequences

I like to reuse code as much as possible and keeps things DRY. But I'm afraid that sometimes it creates too many layers of indirection. It then becomes a chore to find where code exists that is ...
6
votes
1answer
51 views

Pass in parameters instead of multiple functions

I can't quite figure out the best way to approach this. I have two jQuery objects that both are used to set cookies. I then parse the JSON and set a cookie that is either the users height or the users ...
7
votes
1answer
73 views

DRY multiple if statements used to show/hide elements based on slider value

I'm showing and hiding 4 svg paths based on the value of a slider, all is working as expected, but it still feels a little cumbersome. Does anyone know a way to "DRY" it out a little more? jsFiddle ...
4
votes
2answers
77 views

Making CSS rules for links in header more DRY

I want to implement the cleanest amount of CSS through proper use of inheritance. All links need to be a shade of white, so lets say #fff HTML ...
9
votes
2answers
229 views

Implementation of the Strategy Pattern using an interface, abstract class and delegate

The following class was designed to help create a more detailed error message than what's provided by the repository when a user tries to insert text into a column that is > the column max length. The ...
10
votes
2answers
264 views

Monopoly game cards

This functionality is for a Monopoly board game. In particular, when the player lands on Chance or Community Chest, a random card is drawn with a particular set of instruction, a bonus could be paid ...
6
votes
2answers
106 views

Flow control with try catch to reduce redundancy

I've seen a similar question to this but mine's a little more specific. I have the below ...
2
votes
1answer
71 views

Code duplication when converting DTO to String messages

In a payment application a day before and at the same time with some payments some messages(email) needs to be sent. I have a DTO (called EscrowPayment, projected ...
3
votes
5answers
251 views

How can I reduce repetition of these three similar functions? [closed]

I have 3 functions which look like this (simplified): ...
0
votes
1answer
56 views

What are the drawbacks of DRY input validation configuration?

I have designed the following input validation implementation with one goal: DRY. I'd like to know whether it is intuitive and what are the possible shortcomings. ...
4
votes
1answer
48 views

How can I DRY this .ejs file up a bit?

For a few reasons I had to use EJS on a specific page in my Express project. This was previously like 13 lines of code with MustacheJS and a small JSON file. But now that it is hard-coded, it is a ...
6
votes
3answers
231 views

Make PHP code block more elegant

I would like advice on making my code more elegant and straightforward. The code works great, but it lacks these things. ...
0
votes
0answers
74 views

GAE ensuring session-based authentication for every request

I have implemented the webapp2_extras.sessions module in GAE and am adding the same code block to a few classes to ensure the user is logged in, else send them to a login page (passing a return path ...
1
vote
1answer
69 views

DRY version of this one line if/else for property's existence

I have an object for which I wish to modify a property if a condition is met, else leave it virginal. I find my current code to be very repetitive and would instead like to use a more succinct form, ...
6
votes
1answer
216 views

How to avoid duplication and to keep code clean

Here is my C# code that draws scanline of the image to System.Drawing.Graphics. It's quite simple and it's optimized in order to merge neigbour samples with the same color into single rectangle ...
2
votes
2answers
218 views

Javascript DOM Override Review

I'm building an mini-app that will display when changes to the DOM have been made by javascript. I have all of the functions that I can think of listed in the code. Is there a way to consolidate the ...
3
votes
2answers
145 views

Helping to Make My Controller Function DRY

I have the following controller function. What I want to do is make this function do less. Most of this code is just random checks on various things that is also done on most of my other controllers. ...
1
vote
3answers
106 views
4
votes
2answers
136 views

Refactor to reduce code duplication

I have four methods like these (here are only two of them): ...
0
votes
2answers
110 views

How can I DRY this Rails code?

users_controller.rb: ...
2
votes
1answer
152 views

Improve this numeric solver for properties of geometric objects

I'm converting some C# code to F#. Basically it is some geometry classes that can have properties tuned by a numerical solver. I start with a discriminated union of type ...