dry

Is there a good way to avoid duplication of method prototypes in C++?

Most C++ class method signatures are duplicated between the declaration normally in a header files and the definition in the source files in the code I have read. I find this repetition undesirable and code written this way suffers from poor locality of reference. For instance, the methods in source files often reference instance variabl...

Finding ways to not check a db regularly in rails..

Hi all- I have an application wherein the application will need to check whether one user is waiting for another user whenever a page is loaded. I have entries that look like this: def self.up create_table :calls do |t| t.string "user1_id" t.string "user2_id" t.boolean "active", :default=>false t.strin...

Need to make full names in cakePHP

Hi all, If I have a person model with first_name and last_name, how do I create and display a full_name? I would like to display it at the top of my Edit and View views (i.e. "Edit Frank Luke") and other places. Simply dropping echoes to first_name and last_name isn't DRY. I'm sorry if this is a very simple question, but nothing has ...

asp.net MVC ddd DRY vs loose coupling and persistance/data access layer

So as I understand it with good loose coupling I should be able to swap out my DAL with a couple lines of code at the application root. I have 2 DAL written, Linq-to-sql and a JSon file repository (for testing and because I wanted to try out the System.Web.Scripting.JavascriptSerializer). linq to sql will create entities instead of my ...

Which side of the api chasm?

I am torn between to DRY and loose coupling :( I have two sites which you can link your account and then the sites can share data (via a RESTful api...) one site is a media aggregation site and the other is a media store where people can buy digital media (music/photo/video). My boss wants to emulate the itunes store and have a built-...

How to refactor this code?

Please suggest in refactoring this code. Avoid code duplication, mutiple If's public FormDataDTO getDataForFieldFormCHrzntalField(Field field) { FormDataDTO formDataDTO = new FormDataDTO(); CHrzntalField cHrzntalField = (CHrzntalField) field; for (int j = 0; j < cHrzntalField.getFieldCount(); j++) { Field sField = c...

Duck typing: how would you treat this situation.

Hi, Relatively new to python. I recently posted a question in regards to validating that a data type is boolean. [http://stackoverflow.com/questions/1708349/use-a-single-decorator-for-multiple-attributes%5D%5B1%5D The answers given referenced duck typing. I have a simple example, and want to make sure I understand. If my code is: cla...

DRYing my views, helper / method / something else?

Have written some RoR sites in the past, but never bothered too much at DRYing up my views as it's only ever been me looking at the code. Just starting a new site, that is likely to be a collaboration, and need help I call this line multiple times in my views, and from multiple places. <%= Person.find_by_id(rider.person_id).name %> ...

Why isn't DRY considered a good thing for type declarations?

It seems like people who would never dare cut and paste code have no problem specifying the type of something over and over and over. Why isn't it emphasized as a good practice that type information should be declared once and only once so as to cause as little ripple effect as possible throughout the source code if the type of somethin...

When does technical documentation violate the DRY principle?

We had a project where things got in a bit of a mess a while ago because of inexperienced developers. The main issue was the fact that the programmers rushed directly into writing the code after they have read the functional requirements. They did not stop for a moment before and think how they might implement the stuff, so they coded ...

How do I apply the DRY principle to iterators in C++? (iterator, const_iterator, reverse_iterator, const_reverse_iterator)

OK, so I have two (completely unrelated, different project) classes using iterators now. One has iterator and reverse_iterator working as intended, and the other, current one has iterator and a semi-broken const_iterator (specifically, because const_iterator derives from iterator, the code LinkedList<int>::iterator i = const_list.begin()...

wpf DataGridTextColumn refactoring

Hello I am using a DataGrid in a WPF app that has several (literally one for each day of the week) columns which differ only in their data index. A sample of the xaml is below. How can I refactor this into something more DRY? Cheers, Berryl SAMPLE XAML (two of seven columns): <dg:DataGridTextColumn Header="{Binding Source={Stat...

Help to create a generic class to avoid code duplication

I have a simple problem try to stay DRY using Appengine. The 2 functions below are identical except for the object sent as parameter. In reality I have 15 functions like this. I am try to find a way to create a super class or a generic to achieve this. public void deleteRecord(Person s) { PersistenceManager pm = PMF.get().getPersist...

MVVM - Using simple model as it's own view model is a bad practice?

Guess we have simple model, e.g. let it be a Person { Name, Age }. Now we want to display a list of persons. Persons are read-only We don't need to edit them We don't need any additional stuff like presentation properties, etc. Now question is if it is a good practice do not create PersonViewModel class that will probably be ...

Drying up my rails models

I have a couple of models which share a has_many associations, named scopes and validations. What's the best way of drying these models up so they can share the same code? Create a parent class and have these models inherit from that or would I be better off creating a module? This is the type of code I'm looking to dry up: has_many...

Java Inner Class Iterator Problem

I'm having difficulty using an inner Iterator. private List<List<? extends HasWord>> sentences = new ArrayList<List<? extends HasWord>>(); private Iterator<String> wordIterator = new Words(); private class Words implements Iterator<String> { int currSentence = 0; int currWord = 0; @Override public boolean hasNext() { return cur...

How can I extract the code repetition here?

I am trying to extract out the common code pattern here in an extract method, but am having trouble finding the proper type for the type of Presenter. Any help? public bool CanGotoHome { get { return !(CurrentPresenter is IHomePresenter) && IsLoggedIn; } } public bool CanGotoImportanceOfAimsAndObjectives { get { return...

Can we use a custom action with inherited_resources in a DRY manner?

We have a custom action (:register) for our Location model. The supporting code is very similar to a standard :update. Since inherited_resources provided a "template" for us, we copied the update code from actions.rb, changing 'update_attributes' to 'register' and the flash message reflects the different action. This doesn't feel very ...

Django DRY URLs for Model access

Reader's Digest version: How do I get data (either single row if specified or full table) from a model by taking a URL argument of the model's name without hardcoding the URLconfs to match each model? For more details, read on: I'm making an app that has three models, and I want to make a simple view that takes a name of a model, and sp...

Strategy for handling parameter validation in class library

I got a rather big class library that contains a lot of code. I am looking at how to optimize the performance of some of the code, and for some rather simple utility methods I've found that the parameter validation occupies a rather large portion of the runtime for some core methods. Let me give a typical example: A.MethodA1 runs a l...