In an effort to reduce code duplication in my little Rails app, I've been working on getting common code between my models into it's own separate module, so far so good.
The model stuff is fairly easy, I just have to include the module at the beginning, e.g.:
class Iso < Sale
include Shared::TracksSerialNumberExtension
include Shar...
I'm working on several distinct but related projects in different programming languages. Some of these projects need to parse filenames written by other projects, and expect a certain filename pattern.
This pattern is now hardcoded in several places and in several languages, making it a maintenance bomb. It is fairly easy to define this...
I ruined several unit tests some time ago when I went through and refactored them to make them more DRY--the intent of each test was no longer clear. It seems there is a trade-off between tests' readability and maintainability. If I leave duplicated code in unit tests, they're more readable, but then if I change the SUT, I'll have to t...
I keep hearing about the DRY Principle and how it is so important in ASP.NET MVC, but when I do research on Google I don't seem to quite understand exactly how it applies to MVC.
From what I've read its not really the copy & paste code smell, which I thought it was, but it is more than that.
Can any of you give some insight into how I ...
For example, how to avoid writing the 'func_name' twice?
#ifndef TEST_FUN
# define TEST_FUN func_name
# define TEST_FUN_NAME "func_name"
#endif
I'd like to follow the Single Point of Truth rule.
Version of C preprocessor:
$ cpp --version
cpp (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
...
Hey right now I'm using jQuery and I have some global variables to hold a bit of preloaded ajax stuff (preloaded to make pages come up nice and fast):
$.get("content.py?pageName=viewer", function(data)
{viewer = data;});
$.get("content.py?pageName=artists", function(data)
{artists = data;});
$.get("content.py?pageName=instores"...
Hi people
I have an issue with trying to keep AR finders DRY in my application. I have created a blogging application which fetches all the related pages,posts,links,tags and categories for a blog when a user first views it. A sample show action for the Blog controller is shown below:
def show
#find blog by user name
@user= Use...
I'm looking for best practices for using the same data in different places without repeating yourself - this could include configuration or business rules.
Example 1. Data validation rules where you want to validate on the client using javascript, but you want to make sure by validating on the server.
Example 2. Database access where y...
We're using Stored Procedures for every query to the DB. This seems incredibly un-DRY:
Design the table
Design CRUD operation SPs for that table
Design code (preferably a class) to fill parameters and execute CRUD SPs
If we add a single column, or change a datatype, we have to edit the table, a handful of SPs, and a handful of funct...
In the library, right-click on a movieclip that you have written an ActionScript class for and select "Linkage...". Notice that the "Base class" field is not empty (it can't be). It's likely to be flash.display.MovieClip, but it could be something else, depending on what your class inherits from. This base class field is only required wh...
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 class. I would like to share these constants between my JavaScript and PHP code. Is there a DRY (Don't Repeat Yourself) mechanism to share them?
class Constants {
const RESOU...
I normally try to avoid duplication and adhere to the DRY principle. However, I'm wondering about a case like this:
public class Feature {
final static String FEATURE_LABEL = "blah";
public void doSomething() { ... }
...
}
public class FeatureTest {
...
@Test
public void doSomethingShouldMakeSomethingHappen() {...
I'm wondering how others handle this situation... and how to apply the Don't Repeat Yourself (DRY) principle to this situation.
I find myself constantly PIVOTing or writing CASE statements in T-SQL to present Months as columns. I generally have some fields that will include (1) a date field and (2) a value field. When I present this bac...
I am writing an app which - similarly to many apps out there - is 90% regular CRUD things and 10% "juice", where we need nasty business logic and more flexibility and customization.
Regarding this 90%, I was trying to stick to the DRY principle as much as I can. As long as controllers go, I have found resource_controller to really work,...
It's a small thing, really: I have this function that converts dict objects to xml.
Here's the function:
def dictToXml(d):
from xml.sax.saxutils import escape
def unicodify(o):
if o is None:
return u'';
return unicode(o)
lines = []
def addDict(node, offset):
for name, value in node....
I want to use the same {% block %} twice in the same django template. I want this block to appear more than once in my base template:
# base.html
<html>
<head>
<title>{% block title %}My Cool Website{% endblock %}</title>
</head>
<body>
<h1>{% block title %}My Cool Website{% endblock %}</h1>
</body>
</htm...
Here's the deal:
I got two db models, let's say ShoppingCart and Order. Following the DRY principle I'd like to extract some common props/methods into a shared interface ItemContainer.
Everything went fine till I came across the _flush() method which mainly performs a delete on a related object set.
class Order(models.Model, interface...
Hi,
I have some SP that takes year and month:
Create PROCEDURE Report(
@targetYear int,
@targetMonth int
)
select sum(col) where year(dateTime) = @targetYear and month(dateTime) = @targetMonth
Then I have the same thing for year only
Create PROCEDURE Report(
@targetYear int
)
select sum(col) where year(dateTime) = @ta...
How would you get the dreamed DRY ideal in this sample, in the language of your choice:
drawLine(Point(0, 0), Point(w, 0));
int curRowY = 0;
for(int row=0; row<rowHeights.size(); row++) {
curRowY += rowHeights[row];
drawLine(Point(0, curRowY), Point(w, curRowY));
}
drawLine(Point(0, 0), Point(0, h));
int curColX = 0;
for(int col=0; c...
I'm currently using the ASP.NT MVC RC1 to implement a basic timesheet application. I'd like to follow the DRY principles but finding it difficult in one particular case:
One of my views, a partial view actually, has a number of textboxes that represent the number of hours spent on a particular task, one textbox per day of the week. When...