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

learn more… | top users | synonyms

9
votes
1answer
23 views

Creating ShortCut (RightClick) Menus in Access

I'm writing a tool to create shortcut menus for an application that I maintain built on the Access runtime. I compile this app into an *.accde file, so much to my chagrin, all right click menus are ...
4
votes
1answer
58 views

Generic predicate in Java 8

Use Case Creating a generic and reusable predicate with closures that supports Float, Double, Integer, float, double, and integer. Problem Extending "Number" doesn't allow for the modulo operator. ...
12
votes
4answers
2k views

DRY attack and defense

I have these two methods on a class that differ only in one method call. Obviously, this is very un-DRY, especially as both use the same formula. Could anyone give me advice on how to tidy this up? ...
3
votes
0answers
49 views

Debug log wrapper

Please review code correctness, best practices, design and code formatting. I will be adding functionality and most likely additional refactoring, however a stringent review would be welcome before I ...
3
votes
2answers
69 views

Controller: Sign up action clean up

I don't know if it's just me, but I feel like my sign up action method has gotten a bit messy. I think that perhaps instead of setting error messages in a controller, I should set error codes which I ...
12
votes
1answer
260 views

Yet another FizzBuzz

Since today is apparently a good day for...unlikely FizzBuzz implementations, I decided to contribute another, this one in C++: ...
3
votes
1answer
48 views

Rewriting dispatch method

Is it possible to rewrite this piece of code any better when it comes to efficiency and/or readability? ...
5
votes
3answers
71 views

DRYing out a basic image slider

I built a very basic image slider, but I'm still having trouble refactoring. I caught myself reusing same code for clicking the previous/next buttons, selecting a slider dot, and the automated ...
8
votes
1answer
86 views

Reduce duplicate sequences

I am writing a copy paste detector using esprima.js and Hmm. This particular function checks a number of sequences and reduces them. Due to the parsing I might have 2 sequences with the same piece of ...
5
votes
2answers
180 views

How to avoid duplication in my document writer?

I have these two methods which are generating two different xml files whose header section is same and detail section varies. The root node is different for both xml files. Here I have two methods ...
7
votes
1answer
144 views

Less-repetitive code for document-analyzer

I've refactored my code such that every function has only one responsibility. Now I'd like like to work on making it DRY. I'm noticing a lot of duplication in the ...
4
votes
2answers
67 views

Cleaning up validator class

I updated my class with more functionality, but I kind if feel like it's a mess or that it can at least be improved by a bit readability, efficiency and/or DRY wise. Anybody who could see if that can ...
4
votes
2answers
91 views

Validator refactored to be OO

Based on my previous post I completely re-factored my code to make it object oriented. Anything I could improve when it comes to: Object oriented code; Efficiency; Readability. Any other ...
3
votes
2answers
77 views

Getting cars and bicycles from a database and writing them into two different arrays

I've written a simple class which should: get 10 top cars and 10 top bicycles from database write them into 2 different arrays It works, but I'm trying to find a simpler or clearer solution. ...
2
votes
1answer
111 views

Checking if variable is defined before accessing its properties [closed]

I didn't write this but I noticed it in our codebase at work. ...
5
votes
1answer
148 views

DRY + principle of least knowledge + MVC in JavaScript

Is there any way of improving this code? (Here's a JSFiddle with an example and comments) Example: A Hotel greeter can greet guests and accepts tips, but it's impossible to see the total of tips a ...
5
votes
1answer
241 views

Code seems repeated, except for the callback function

I've written some JavaScript code: ...
5
votes
1answer
50 views

Avoiding repetitive code for timestamping and updating status

This is some boilerplate I found myself writing on a new abstract class. It seems ripe for refactoring, but I'm not sure the best way to implement it more effectively. Is there a pattern for these ...
3
votes
1answer
69 views

Breaking after one of several string replaces occur

I have a script that matches a string against ~20 different regexs for the purpose of changing it. They are ordered and formed that the string will only ever match against one. How can I avoid ...
5
votes
2answers
108 views

Converting bootstrap file from procedural code to OOP

My bootstrap file contained procedural code, but after stumbling upon this answer I tried to make my bootstrap object oriented. This is my attempt so far, and I have a feeling that I'm failing at it. ...
7
votes
7answers
789 views

DRY-ing jQuery code for portfolio site

I'm currently working on my portfolio site and it's all great, but I'm unsure how to DRY my jQuery. I'm repeating myself a lot in the jQuery and it's just messy. HTML: ...
3
votes
1answer
82 views

Validator Readability and Efficiency

This is my first validator I have created myself and I was wondering if there is anything about it that I could improve as far as: Code readability Code efficiency Note: The reason why I put an ...
4
votes
1answer
131 views

Are my filter functions DRY enough?

Here's a function I wrote - am I getting DRY about right? I could add another argument to paramFilter maybe, for even less reuse. Or have I gone too overboard as it ...
0
votes
1answer
73 views

How to write this code more efficient and simplify creation of dependency objects?

How can I write my code more efficient (not repeating same code)? And is there a solution that simplifies the way of having to create a lot of dependency objects over and over again whenever I ...
2
votes
1answer
94 views

Making my User model class code more modular, and correct

This is my first User model I created. And I wanted to know if there are any good ways I can improve my code? It works with sessions, database and cookies. I feel like some parts are somewhat ...
4
votes
3answers
143 views

Changing the foreground and background colors of substrings based on ANSI escape codes

I am checking for particular keywords in a string, and then changing the foreground and background colors of substrings based on the keywords. Following is the snippet for checking the background ...
4
votes
2answers
73 views
2
votes
2answers
109 views

Is this how an MVC controller supposed to be?

This is the controller I created for my MVC framework, and I think I finally got it right. Anything I can do to make the code more efficient? Is this how a MVC controller is supposed to look like? ...
1
vote
1answer
65 views

RequestHandler: Is my code clean?

I've built a simple class RequestHandler that does exactly what I want without any extras I won't be utilizing. When needed I will expand. I'm passing this object ...
2
votes
1answer
155 views

Router for MVC framework: Is it OO and good to go?

Am I utilizing dependency injection correctly? Any parts of my class that I should decouple? Anything I could improve in my code when it comes to OO PHP (and MVC)? The class routes URLs based on ...
2
votes
4answers
315 views

Complex boolean logic vs DRY

I have some code: ...
3
votes
1answer
112 views

Find a better logic to remove duplicated code from two different methods

I have to update a class property with the method name and then call a method that executes some code based on this property. The code is the same in both methods, but I am not seeing a way to remove ...
1
vote
3answers
116 views

Does my input helper class look good?

I'm new to OOP PHP and I created a simple input helper class. And was wondering if it's good? Are my dependencies good? Also the reason I'm not throwing an exception with the get method is that I ...
2
votes
1answer
79 views

Providing core functionality orthogonal to business logic in Dart

Below is a simple Trade class with minimal business logic: primarily a method to get market value associated with the trade. But the trade needs the following pieces of core functionality, orthogonal ...
2
votes
1answer
53 views

Rails preventing ajax view duplication

I have a website where people can write articles and publish/unpublish them. This is done via single button on the page: ...
3
votes
1answer
81 views

Shortening if-statements of displaying errors

Is it possible to shorten this piece of PHP code? Honestly, I think it does not look clean but like a mess. ...
7
votes
2answers
110 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
655 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
364 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
52 views

Refactoring scoring algorithm

I have the following code which I feel that I must refactor, but not sure how to do it. ...
2
votes
0answers
18 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
986 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
179 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
58 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: ...
10
votes
1answer
140 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
65 views

Shorter way of writing my displayError() function?

Is there a way I can write this function with less code? jQuery ...
2
votes
2answers
104 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
107 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
274 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
236 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? ...