Don't Repeat Yourself, a software development philosophy which aims at reducing redundancy and code repetition.
3
votes
4answers
102 views
C++ vectors sort ascending/descending
How can I eliminate repetition from this code?
std::vector<std::wstring> vec;
bool descending;
if (descending)
{
std::sort(vec.begin(),
vec.end(),
...
1
vote
2answers
61 views
How can I achieve DRY principle in this code?
In the following piece of code I use the same trick three times. But cannot figure out how to write a common function that will do it for all of them. I know there is a toggle method in jQuery that ...
12
votes
8answers
320 views
Is there a better way to code this block of C code?
This was a homework assignment that I'm now done with - I submitted it as is. However the fact that I needed to use the same code twice bugged me... The double code is:
printf("Enter a distance in ...
2
votes
2answers
100 views
Whats a better way to do these nested if statements?
I forgot to mention using the result of bar to calculate foo's value in the question I asked here.
The function bar only needs to be called if conditionA is true. But when the result of bar ...
3
votes
4answers
323 views
Whats a better (DRY) way to do this if statement
The function bar only needs to be called if conditionA is true. But when the result of bar (conditionB) is false, I want to run the code that would have run if conditionA had been false. Is there a ...
2
votes
2answers
125 views
How can I redesign these classes to take advantage of interfaces?
I'm writing a card game (Dominion) as a pet project. I'm new to C++ but not programming.
A player has a deck, containing the hand and cards in play (tableau). Outside the player, there are piles of ...
2
votes
1answer
88 views
Cross-language Constants
Background
Developing a web application that leverages multiple programming languages. The data flow resembles:
Browser » PHP » PL/SQL » XML » XSLT » XHTML + JavaScript » Browser
Using different ...
0
votes
1answer
36 views
Simplifying and improving (namely DRY) for flight info fetcher
I've put together this simple fetcher for text data (which I just copy and pasted from a flight info website) - it takes in text data, and spits out an array of objects containing values for each ...
3
votes
2answers
64 views
How to reduce duplication among these ruby methods?
I have three methods that are really similar but do slightly different things. This doesn't feel very DRY to me, but I can't think of a way to reduce the duplication. Here are the methods, I think ...
1
vote
0answers
42 views
Optimize jQuery plugin according to DRY-principle [duplicate]
Possible Duplicate:
Optimize jQuery plugin according to DRY-principle
According to the DRY-principle, any ideas how to write this a bit shorter?
jQuery.konami = function(fn, code) {
// ...
3
votes
2answers
45 views
Optimize jQuery plugin according to DRY-principle
According to the DRY-principle, any ideas how to write this a bit shorter?
jQuery.konami = function(fn, code) {
// ↑ ↑ ↓ ↓ ← → ← → B A
code = code || [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
...
2
votes
2answers
111 views
Can someone help me DRY up these jQuery each loops?
I just posted this on the Stack Exchange, but was told I should post it here:
function redundantSee() {
var optionSet1 = $('.wrapper:eq(0)'),
optionSet2 = $('.wrapper:eq(1)');
...
2
votes
2answers
313 views
How can I make my Jquery code less repetitive?
I'm making an avatar creator with Jquery where users can select and change hair, eye and skin colour. The page is a form with different values and when the user clicks on the form options the values ...
2
votes
0answers
106 views
How might I make this code more DRY?
I have the following Ruby code in an RSpec file:
describe "order" do
before do
LIST_LENGTH ||= 10
@skills = FactoryGirl.create_list(:skill, LIST_LENGTH)
@developer = ...
5
votes
1answer
160 views
scopes chaining by OR
How can i DRY these scopes?
scope :reputed, -> {
joins{reputations.outer}.
where{['coalesce(rs_reputations.value, 0) > ? OR purchases.force_active = ?', LOWEST_VOTE, true]}
}
...
1
vote
2answers
177 views
Code fragment where I am repeating myself
I have two methods here that does the same thing. get the user input and validate them.
if they are enter a letter program will prompt him again to enter a number after that if its a number it will ...
2
votes
3answers
184 views
Clean up this Ruby code under DRY principle
I've got the following code, which works, but seems repetitive. Under DRY principle, how can I clean this up?
puts "Blurt out a word"
word = gets.chomp
word_list = []
word_list.push word
until word ...
2
votes
1answer
279 views
How to load content without repeating code using jQuery load method
A while ago I used this code to load content into a div using jQuery load. I repeated the code for all the clicks to load different pages in the same div.
$("#button1").click(function(){
...
0
votes
1answer
38 views
Is there a better way to update fields in an web app?
This is the stripped down version of my update action for a Posts (blog post) controller:
Posts.update = function(req, res){
_.extend(req.post, {
title: req.body.title
, author: ...
2
votes
1answer
95 views
Assign local-variables in constructor
How to make this code in constructor more DRY?
Is there some more concise way to assign variables passed through object?
class Ball
constructor: (args) ->
@name = args.name
@x = ...
1
vote
2answers
98 views
Rails - Loading data in controllers
I am refactoring my controllers, trying to improve the way common data is loaded for the actions.
Initially I was using before_filter methods to do this but read that helper methods were preferred.
...
3
votes
1answer
516 views
Creating a database class in PHP with MySQLi
I am creating a database class in PHP but I feel that there's something wrong with my code. Is there any suggestion to refactor this? I feel like there's something wrong and missing in this code.
...
2
votes
0answers
59 views
How do I DRY this code? [duplicate]
Possible Duplicate:
How do I DRY this code?
Cross posting from StackOverflow by suggestion
I have two main problems with a chunk of code. I need to interpolate 2 different models in a ...
1
vote
1answer
188 views
How do I DRY this code?
I have two main problems with a chunk of code. I need to interpolate 2 different models in a specific order in a list.
In the world of casinos, there are different types of games and jackpots. In ...
2
votes
2answers
69 views
Inserting data in the database through POST
My code here is completely working, but I feel like I destroyed or didn't follow the DRY rule, what suggestions can you give to me for this code??
<?php require_once("./includes/Utilities.php") ...
2
votes
2answers
86 views
Username verification class
Everything in this code is completely working, but I still feel that this code needs to be refactored. any suggestions?
<?php
class Db_CheckUsername{
protected $_conn;
...
2
votes
2answers
74 views
JavaScript optimization
I'm pretty sure there's a way to make this "3 times" duplicated code into only one. Any idea how to do this?
if (typeof sync.create!='undefined') {
for (var i = 0; i <sync.create.length; i++) ...
1
vote
1answer
79 views
Shortening a webshop page
I am making a simple webshop page where I need to add a couple of products (and their prices). The shop consists of less than 10 products so therefore I decided to build my own solution since it is ...
2
votes
1answer
155 views
Is there a better way to do a Luhn check?
I feel like I should not be duplicating the code to gather the credit card number, but I am not sure how best to do it. Any suggestions?
$('input[name="payment\[cc_number\]"]').keyup(function() {
...
2
votes
1answer
98 views
Removing Repeating Stuff from the code
My Question is-
I have two string variables site_inclusion and site_exclusion. And if site_inclusion has some values, then I don't care what values site_exclusion contains, means site_inclusion ...
1
vote
1answer
148 views
Does this code follow loose coupling pattern or should be refactored/re-designed?
I've to adming i don't like this design.
The main class (SMSHelper) is responsible of query a REST web service which in turn returns an XML string. This helper is going to return a new SMSCreditInfo ...
1
vote
2answers
279 views
Bubble sort algorithm in Ruby with tests
As a matter of practice, I tried implementing a bubble sort algorithm in Ruby. I'm especially interested in creating clean DRY and KISS code and keeping things readable, but efficient. Any hints to ...
1
vote
1answer
163 views
Downsampling boundaries of a 2D array
I have a linearized 2D array u (block_height * block_width) containing the values of a physical quantity over a regular 2D mesh. I need to downsample boundaries (top, bottom, left, right) of this ...
4
votes
1answer
158 views
Is this violating the DRY principle?
I feel that I am repeating myself a lot with this HTML/PHP code. Am I right, and is there a maintainable way of reducing the amount of repetition in the code?
mydomain/index.php:
<!DOCTYPE ...
3
votes
2answers
195 views
How to avoid repetition
The program is supposed perform discrete mathematics operations on a number of conjunctive statements (see lines 34 - 50). Currently I just have it so they print out the tables in 0's and 1's, but ...
1
vote
2answers
1k views
Get device orientation
Here is my code:
// get orientation of device
getOrientation();
// animate
var num = 400;
if( $('body').hasClass("landscape") ) {
$('.example').animate({'bottom', 0});
} else {
...
3
votes
4answers
268 views
Duplicate code in nested if statement
I have some code that looks like this:
if (condition1) {
doSomeObjectSetup();
try {
saveObjectToDatabase()
return theObject;
} catch (ValidationException) {
...
2
votes
3answers
1k views
Simple jQuery validation script works but it uses a ton of if/else statements
I've a jQuery validation script to check all form fields for a valid value and prevent form submission and display an error message if any fields fail. It was requested that the validation script not ...
3
votes
1answer
136 views
When to use a new variable vs string interpolation?
I wrote a script that I decided to refactor so I could add functionality to it as my coworkers think of it. I only saved four lines in the effort, but the main change is I removed both methods and ...
5
votes
3answers
258 views
Does using a lambda make this code more DRY?
I started out with a function having code duplication like this:
private static void GetAndSaveResources(string url)
{
...
if (url.Contains("[" + "access_id" + "]"))
...
2
votes
1answer
89 views
Select records and fill hash
I use ruby 1.8.7. I have method wich select records and fill hash. In my opinion the code is not dry. Could somebody help me to refactor it and make it shorter and more elegant?
def fill_attributes()
...
1
vote
2answers
163 views
should DRY apply to unit tests as much as production code
I have a unit test method that looks like this:
...
113 CPPUNIT_ASSERT( !m_pInputFilter[0]->SendPacket() );
114
115 CppUnitUtil::CUnitTestTimeline::GetInstance().Advance( 1, CppUnitUtil::Seconds ...
2
votes
4answers
236 views
Make this C# code more DRY
public sealed class LinkXPathRepository : ILinkXPathRepository
{
private static readonly ILog _log = LogManager.GetLogger(typeof(LinkXPathRepository));
internal ILink Parse(Uri endpoint)
...
4
votes
1answer
396 views
Prepared statements syntax review
Migrating to using prepared statements and would like some feedback on CRUD modules, concerned with syntax (usage and DRY) and speed:
START:
<?php
// This page is for deleting a user record.
// ...
1
vote
2answers
158 views
Refactoring custom validator using lots of if's
I have a custom validator that checks the min and max score of different sporting leagues -- e.g., MLB, NBA, NFL, NCAAB, etc.
Here's short version of what it looks like:
class ScoreValidator < ...
5
votes
3answers
249 views
How can I make this code more DRY?
This code is for a simple language quiz. It fetches two words and related audio files via a JSON call, presents the user with an image that matches one of the words, and challenges the user to make ...
1
vote
1answer
428 views
Javascript get item in object code
So I have some Javascript code that resembles the following:
var mylibrary = new (function ()
{
this._getLibraryObj = function ()
{
var newLibraryObj = {};
var libraryData = ...
2
votes
2answers
158 views
Duplicated code in web service consumption
I have a set of classes that abstract away calls to a set of web services. I have 6 classes in this particular group, 4 of which contain a simple function that, while small, is still duplicated. What ...