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
13
votes
4 answers

"inheriting" ASP.NET MVC sites from a common template app? (multi-tenancy)

We're building about 10 ASP.NET MVC sites which have a common set of features (and corresponding URLs, Routes, Controllers, Actions, and Views). The sites will also all share a base set of domain objects (e.g. users, companies) and base attributes…
Justin Grant
  • 44,807
  • 15
  • 124
  • 208
13
votes
7 answers

JSLint "eval is evil." alternatives

I am have some JavaScript functions that run on both the client (browser) and the server (within a Java Rhino context). These are small functions - basically little validators that are well defined and don't rely upon globals or closures -…
Jake Feasel
  • 16,785
  • 5
  • 53
  • 66
12
votes
4 answers

Share Constants Between PHP and JavaScript

Possible Duplicate: Pass a PHP string to a Javascript variable (and escape newlines) I have several constants in a PHP application I'm developing. I've defined a Constants class and the defined the constants as const VAR_NAME = value; in this…
Brian Fisher
  • 23,519
  • 15
  • 78
  • 82
12
votes
3 answers

How to keep code DRY in Golang

EDIT++: How to not to repeat my code in Go? type Animal interface { Kingdom() string Phylum() string Family() string } type Wolf struct {} type Tiger struct {} func (w Wolf) Kingdom() string {return "Animalia"} func (w Wolf) Phylum()…
I159
  • 29,741
  • 31
  • 97
  • 132
12
votes
5 answers

using yield in C# like I would in Ruby

Besides just using yield for iterators in Ruby, I also use it to pass control briefly back to the caller before resuming control in the called method. What I want to do in C# is similar. In a test class, I want to get a connection instance, create…
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
12
votes
2 answers

Using async await when implementing a library with both synchronous and asynchronous API for the same functionality

I've got a few questions about how to provide both synchronous and asynchronous implementation of the same functionality in a library. I am gonna ask them first and then provide the example code below (which is actually quite a bit, but in fact it's…
Ceco
  • 1,586
  • 3
  • 16
  • 23
12
votes
6 answers

How do you keep your business rules DRY?

In the perfect application every business rule would exist only once. I work for a shop that enforces business rules in as much as possible in the database. In many cases to achieve a better user experience we're performing identical validations…
Mario
  • 6,572
  • 3
  • 42
  • 74
12
votes
3 answers

ASP.NET MVC - How to achieve reusable user controls and maintain DRY?

First post so please be gentle :) When creating user controls in ASP.NET MVC, what is the best way to structure the code so that the controllers that invoke views that use the user controls do not all have to know so much about the controls? I would…
user241255
  • 123
  • 1
  • 5
12
votes
2 answers

How to re-use NGINX proxy settings in several locations

I have the need to restrict access to certain files based on a query string parameter. I have an NGINX proxy server that sits in front of several other nginx web servers for load balancing. I have decided to enforce this query string parameter at…
bmckim
  • 143
  • 5
12
votes
6 answers

DRYing Views in Rails (number_to_currency)

I have code similar to: number_to_currency(line_item.price, :unit => "£") littering my views in various models. Since my application deals only in GBP (£), should I not move this into each of my models so that line_item.price returns the string as…
Gav
  • 11,062
  • 7
  • 33
  • 35
11
votes
3 answers

Making Grails controllers more DRY?

I am looking for ways on how to cleanup my Grails controller code. In various controllers i more or less have the same logic.. get the object check if it exists etc.. Is there a suggested way on making controller actions reuse common code? ---…
Marco
  • 15,101
  • 33
  • 107
  • 174
11
votes
1 answer

Why ReadOnlySpan may not be used as a type argument for generic delegates and generic methods?

I understand why ReadOnlySpan may not be used as a type argument for generic classes. ReadOnlySpan is stack only and therefore it cannot be used as field types, field members live in the heap like its container object. However return values and…
Jesús López
  • 8,338
  • 7
  • 40
  • 66
11
votes
3 answers

Exposing parameter types in a perfectly-forwarding function avoiding code repetition

I have an annoying scenario where I need to defer the initialization of some object state and allow the user to construct one on demand. E.g. // user code context c; // ...do something... c.initialize_state(a, b, c); // library code class…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
11
votes
4 answers

Simplifying multiple boolean checks into a single one

In one of our tests, we have the following set of…
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
11
votes
5 answers

Haskell: How to organize a group of functions that all take the same arguments

I am writing a program with several functions that take the same arguments. Here is a somewhat contrived example for simplicity: buildPhotoFileName time word stamp = show word ++ "-" ++ show time ++ show stamp buildAudioFileName time word = show…
DJG
  • 6,413
  • 4
  • 30
  • 51