Questions tagged [dry]

Don't Repeat Yourself, a software development philosophy which aims at reducing redundancy and code repetition. Questions regarding how to refactor code are better suited on codereview.stackexchange.com

DRY, Don't Repeat Yourself, is a software engineering principle aimed at reducing redundancy and repetition of information of all kinds.

Note that questions regarding how to refactor code are better suited on CodeReview.

2196 questions
49
votes
2 answers

How to reduce code duplication when dealing with recursive sum types

I am currently working on a simple interpreter for a programming language and I have a data type like this: data Expr = Variable String | Number Int | Add [Expr] | Sub Expr Expr And I have many functions that do simple things like: --…
47
votes
5 answers

How to reuse beforeEach/afterEach in Jasmine JS?

When writing tests with JasmineJS I have many tests that have similar beforeEach/afterEach code. Is there a way to implement an inheritance model using JasmineJS test suites? I can group all tests in a single describe but in this case I will end…
Adi Roiban
  • 1,293
  • 2
  • 13
  • 28
44
votes
3 answers

In which folder should I put "global" shared partial templates?

I am using Ruby on Rails 3.0.7 and I am planning to use partial templates. All classes in my application would use same partials so I have to decide where to located all those. Is it a good idea to put "global" shared partial templates in the lib…
Backo
  • 18,291
  • 27
  • 103
  • 170
43
votes
2 answers

Django - use reverse url mapping in settings

A few of the options in the django settings file are urls, for example LOGIN_URL and LOGIN_REDIRECT_URL. Is it possible to avoid hardcoding these urls, and instead use reverse url mapping? At the moment this is really the only place where I…
TM.
  • 108,298
  • 33
  • 122
  • 127
42
votes
4 answers

Template function as a template argument

I've just got confused how to implement something in a generic way in C++. It's a bit convoluted, so let me explain step by step. Consider such code: void a(int) { // do something } void b(int) { // something else } void function1() { …
Kos
  • 70,399
  • 25
  • 169
  • 233
36
votes
4 answers

Best practice for reusing python code

I have write a python library app(which contains several *.py files). And several of my python projects need to reuse the code in the library app. What's the recommended best practice for reusing python code? Currently I have thought out three…
Tyler Liu
  • 19,552
  • 11
  • 100
  • 84
36
votes
4 answers

Rails 3 - Restricting formats for action in resource routes

I have a resource defined in my routes. resources :categories And I have the following in my Category controller: def show @category = Category.find(params[:id]) respond_to do |format| format.json { render :json => @category } …
Mike
  • 16,690
  • 2
  • 19
  • 25
33
votes
7 answers

Gulp task with different source depending on arguments

I want to accomplish something simple using gulp. I want to write a generic method to move files to an output directory from a particular source directory. pretend we have something like so var args = require('yargs'); function…
jth41
  • 3,808
  • 9
  • 59
  • 109
32
votes
3 answers

Is it possible to share a masterpage between MVC and webforms?

I am adding MVC to a project that has MANY legacy webform pages. This works fine. However, I currently have a separate masterpage for MVC and for the webforms. The two master pages produce essentially identical output. I'd really like to kill…
Craig Quillen
  • 2,057
  • 3
  • 23
  • 30
31
votes
2 answers

Does validation in CQRS have to occur separately once in the UI, and once in the business domain?

I've recently read the article CQRS à la Greg Young and am still trying to get my head around CQRS. I'm not sure about where input validation should happen, and if it possibly has to happen in two separate locations (thereby violating the Don't…
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
31
votes
5 answers

What's the least redundant way to make a site with JavaScript-generated HTML crawlable?

After reading Google's policy on making Ajax-generated content crawlable, along with many developers' blog posts and Stackoverflow Q&A threads on the subject, I'm left with the conclusion that there is no way to make a site with only…
jqp
  • 657
  • 1
  • 8
  • 18
28
votes
2 answers

Best way to handle view and helper-only constants in Rails

I have a constant that is only used in views, but it's used in different ways in different places. It's an array of option names, and is used for select boxes, but I also use this in other views to see if strings are found in this array, and…
William Jones
  • 18,089
  • 17
  • 63
  • 98
28
votes
6 answers

Localized project with several targets with localized app names

I have recently merged together 5 of my stand-alone projects into one project to have a common code base. So now I have one project with 5 targets instead. Each target has the same fileset, except for some files which differ for each target (such as…
Paul Peelen
  • 10,073
  • 15
  • 85
  • 168
25
votes
3 answers

Java method accepting different functional interface types - possible?

First of all, sorry for the bad title, but I find it somewhat difficult to summarize my issue in one short sentence... There's some code in our software which I'm quite unhappy with. It goes like this: @FunctionalInterface public interface…
danB
  • 311
  • 2
  • 5
25
votes
4 answers

Why are particular C data types declared in more than one standard header file?

For example, C11 dictates that size_t should be declared in the following header files: stddef.h stdio.h stdlib.h string.h time.h uchar.h wchar.h When reading C11, I found there are many other data types declared in more than one standard header…
Astaroth
  • 2,241
  • 18
  • 35