dry

Keeping Drop-downs DRY in a web app

I'm writing a CMS for various forms and such, and I find I'm creating a lot of drop-downs. I don't really feel like mucking up my database with tons of random key/string value tables for simple drop-downs with 2-4 options that change very infrequently. What do you do to manage this in a responsible way? This is language-agnostic, but ...

DRY and similar queries

Working on a particular application, I keep writing very similar queries, again and again. They're not exactly the same, but are of very similar form, and embedded in almost identical chunks of code, e.g., $Mysqli = new mysqli; if ($Stmt = $Mysqli->prepare("SELECT foo FROM tblFoo ...

Circular dependencies versus DRY

I'm designing a re-usable class library that contains 2 assemblies (amongst others) named core.xml.dll and core.string.dll. The xml assembly references the string assembly in order to use some string helper methods. However now there is an string method that would be benefit from using a method contained in the xml assembly. If I...

Avoiding duplication in WPF (following DRY)

Consider the follow 2 XAML snippets (which are side-by-side in the file): <Button x:Name="BuyButton" Margin="0,0,1,1" IsEnabled="{Binding CanBuy}" > <StackPanel DataContext="{Binding Product}"> <TextBlock Foreground="Red" Text="BUY" /> <TextBlock Foreground="Red" Text="{Binding ...

How can I use the DRY principle to in ASP.NET MVC to refactor this code?

I have several methods in one of my controllers that does this: ViewData["Customers"] = LoadCustomers(); ViewData["Employees"] = LoadEmployees(); ViewData["Statuses"] = LoadStatuses(); etc...... Here is LoadCustomers(), but LoadEmployees, LoadStatuses and all the others are virtually the exact same logic: private static SelectLis...

DRY LINQ statements for tables with common columns

Here's an interesting problem. Is there a way to write some code using LINQ to SQL which is capable of performing a table UPDATE knowing only that the table it is given contains columns x, y, z but not knowing at compile time which table it is dealing with? I have several tables in my DB schema which share some columns and I need to app...

How would you enforce DRY (Don't Repeat Yourself) in a SQL script?

Hi, I'm changing a database (oracle) with a script containing a few updates looking like: UPDATE customer SET status = REPLACE(status, 'X_Y', 'xy') WHERE status LIKE '%X_Y%' AND category_id IN (SELECT id FROM category WHERE code = 'ABC'); UPDATE customer SET status = REPLACE(status, 'X_Z', 'xz') WHERE status LIKE '%X_...

Are there any code DRYer tools out there?

I have a large code base and there is lots of repeated, or nearly repeated code all over the place, it's about as unDRY as code can get, but tracking the "duplicates" is hard, so I was wondering if there are any tools for finding potential DRYable code, something like a diff tool or a Hamming distance analizer, don't need language specif...

What duplication detection threshold do you use?

We all agree that duplication is evil and should be avoid (Don't Repeat Yourself principle). To ensure that, static analysis code should be used like Simian (Multi Language) or Clone Detective (Visual Studio add-in) I just read Ayende's post about Kobe where he is saying that : 8.5% of Kobe is copy & pasted code. And that is with t...

Rails - Two controllers or adding actions?

Designing a web app with a admin section and a public facing section. It feels like having a public facing controller just for "index" and "show" is a bit redundant. All the suggestions I've read suggest a namespace for admin, which is fine. I just wonder if I should have one controller with an addition action, say "list_public" or somet...

conditional view/layout

Say there is a product controller which you want to have an index (list products) action. Easy. Now say you have an admin and store parts in your project. Both need to list products, but in a slightly different manner (store's one shouldn't have this edit product link for instance). They also use different layouts. So far my idea is to ...

DRY Rails Master Templates?

Is there a simple way to define a master template for my whole rails application? If not, what's the best way to reuse my templates so that I'm not copy and pasting the same template into a bunch of layout files? ...

CSS vs DRY

You're creating an HTML layout. Let's assume that you don't need the benefits of multiple stylesheets, that a small increase in HTML size is not a concern, and that you have a style which will only be used once. I'm often in favour of using an inline style here, as I view the repetition of your CSS class name or ID as the cost of an abs...

Best practices for populating rails with processed data

I've been working for some months on a program for processing some data, and it's now at a stage where rather than displaying information (stored using ActiveRecord) via the command-line, I'd like to display the processed information via a Rails app. The first question I'm facing is whether I should have the data processing and the data...

Guidelines for applying DRY in Haskell function definitions

I have a question about whether or not a specific way of applying of the DRY principle is considered a good practice in Haskell.I'm going to present an example, and then ask whether the approach I'm taking is considered good Haskell style. In a nutshell, the question is this: when you have a long formula, and then you find yourself needi...

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 the webforms one and just use the MVC master page with all my pages and stay DRY. Not bei...

Writing easily modified code

What are some ways in which I can write code that is easily modified? The one I have learned from experience is that I almost always need to write one to throw away. That way I have developed a sense of the domain knowledge and program structure required before coding the actual application. ...

try... except... except... : how to avoid repeating code

I'd like to avoid writting errorCount += 1 in more than one place. I'm looking for a better way than success = False try: ... else: success = True finally: if success: storage.store.commit() else: storage.store.rollback() I'm trying to avoid store.rollback() i...

Is there a (necessary) redundancy in the migration format Add x to y?

To add the phone column to the tickets table, I can write: ruby script/generate migration AddPhoneToTickets phone:string There seems to be a redundancy here. But is it necessary? Aren't we repeating ourselves by being required to specify "phone" both in the name of the migration (AddPhoneToTickets) as well as in the column definiti...

DRY this method

I need help making this method generic. It is repeated about ten times to get lists for different web list controls (substituting "MyType" for the type used in the particular control). private static IList<MyType> GetList(RequestForm form) { // get base list IMyTypeRepository myTypeRepository = new MyTypeReposito...