In keeping with the DRY-principle I try to use partials as soon as I am repeating a particular pattern more than once or twice. As a result, some of my views consist of ten or more different partials. I am worried that this might have a negative effect on the overall performance. Some programming books compare the use of partials with th...
Similar question but not quite the same thing
I was thinking that with extension methods in the same namespace as the interface you could get a similar effect to multiple inheritance in that you don't need to have duplicate code implementing the same interface the same way in 10 different classes.
What are some of the downsides of doin...
I'd like to adhere to the Don't-Repeat-Yourself principle, but sometimes when I write PHP together with HTML and CSS, if I re-use the same code for different situations, my code soon will have so many if-then-else that the code is not easily maintainable.
This may be a bigger issue if Smarty, the templating engine is used, because most ...
Whenever I load a blog post onto the page with Ajax, I set the page <title> to "My Blog - BLOGPOST_TITLE".
Of course "My Blog - " appears in my application layout as well.
The question is, how do I tell my Javascript about the string "My Blog - " without duplicating it in my code?
...
I'll preface this with saying I'm day 8 into life as a C# developer.
For a number of DomainModels in the project I am working on, I need the ability to filter all records in a table given what a user submits in a review/search form.
Currently the 2 cent short tour is:
Form submits to FooController/review.
Review then grabs all key/va...
Let's say we have a grails web application exposing several resources.
tags
urls
users
The application has a classical web-interface which the users interact with and some administration.
We want to expose the resources from the application to clients via a RESTful API and we don't want that part of the app to clutter up the control...
Disclaimer: I am a layperson currently learning to program. Never been part of a project, nor written anything longer than ~500 lines.
My question is: does defensive programming violate the Don't Repeat Yourself principle? Assuming my definition of defensive programming is correct (having the calling function validate input instead of t...
I'm currently about two-and-a-half weeks in to my first ASP.Net MVC application, and so far, I love it.
This current project is a port of an ASP.Net WebForms project, and I am trying to maintain functionalty. All is going well.
However, I find myself repeating... myself.
For example, In my BaseController class, in my BaseViewPage, in...
This is part of an events page that can be filtered by date (using pre-defined date ranges or a date picker).
I want to avoid repeating the whole foreach ($days as $day_number)... etc. loop for every condition.
I guess that whole loop could be moved to a function, but I'm not sure how to implement it.
<?php
// open the db connection
...
How can I make my following code "DRY" (Dont Repeat Yourself)
- (void)updateLetterScore { // NOT DRY... Must fix
if (percentScore < 60.0)
letterLabel.text = [NSString stringWithFormat:@"F"];
if (percentScore > 59.0 && percentScore < 64.0)
letterLabel.text = [NSString stringWithFormat:@"D-"];
if (percentScore > 64...
Currently I am using this to strip out whitespaces.
class Newsletter < ActiveRecord::Base
before_validation :clean_up_whitespace
end
def clean_up_whitespace
fields_to_strip = ['title','notes']
fields_to_strip.each { |f|
unless self.attributes[f].nil?
self.attributes[f].strip!
end
}
end
I want to do something simi...
I have been reading up on multiple PHP frameworks, especially the Zend Framework but I am getting confused about the proper way to go forward.
Zend Framework does not use ActiveRecords but instead uses the Table Data Gateway and Row Data Gateway pattern, and uses a DataMapper to map the contents of the Row Data Gateway to the model, bec...
Hi,
I have recognized the fact that i do not have a clear understanding of how forms and business logic layers should be distinctly separated. Especially in business apps this is hard to accomplish at some times as to keep the UI clean from business logic and to be able to minimize repetition among different forms that share some common...
I have developed contingent country-state select dropdowns, and I'd like to factor out this behavior to an Address model so that I don't have to copy the dynamic behavior (more or less split between view and controller) each and every time I want the user to be able to enter a full address.
Basically I'm trying to dip my toes a little d...
I'd like to add parts of the source code to the XML documentation. I could copy & paste source code to some <code> elements, like this:
/// <summary>
/// Says hello world in a very basic way:
/// <code>
/// System.Console.WriteLine("Hello World!");
/// System.Console.WriteLine("Press any key to exit.");
/// System.Console.ReadKey(...
I have an OptionsController, which contains an action account. The corresponding view has three forms, which post to three different actions, update_profile, update_user and change_password. Each action runs and then should redirect back to action, where the view is set up again and rendered.
I was trying to be DRY and create an after_f...
I know it's possible to use validators to check data input in the presentation layer of an application (e.g. regex, required fields etc.), and to show a message and/or required marker icon. Data validation generally belongs in the business layer. How do I avoid having to maintain two sets of validations on data I am collecting?
EDIT: I ...
This seemed to spark a bit of conversation on another question and I
thought it worthy to spin into its own question.
The DRY principle seems to be our weapon-of-choice for fighting maintenance
problems, but what about the maintenance of test code? Do the same rules of thumb
apply?
A few strong voices in the developer testing communit...
I have some code that gets the current logged in user.
userID = request.session.get("_auth_user_id")
if userID:
loggedin_user = User.objects.get(pk=int(userID))
else:
loggedin_user = None
I want the username to show up on every page.
At the moment I am putting the code in every view and passing the user object to e...
In the near future, I will be inheriting a somewhat large project. I've been making some small updates to it recently, and noticed that parts of it could use some refactoring, since there are methods that perform the same operation with a small difference.
I was wondering if there is a tool that will take a bunch of source code and f...