The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Are you a Desiccant?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Obie Fernandez

Posts: 608
Nickname: obie
Registered: Aug, 2005

Obie Fernandez is a Technologist for ThoughtWorks
Are you a Desiccant? Posted: Dec 15, 2005 11:31 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Obie Fernandez.
Original Post: Are you a Desiccant?
Feed Title: Obie On Rails (Has It Been 9 Years Already?)
Feed URL: http://jroller.com/obie/feed/entries/rss
Feed Description: Obie Fernandez talks about life as a technologist, mostly as ramblings about software development and consulting. Nowadays it's pretty much all about Ruby and Ruby on Rails.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Obie Fernandez
Latest Posts From Obie On Rails (Has It Been 9 Years Already?)

Advertisement

Desiccant: A substance used as a DRYing agent

Applied to programming, someone who is an expert follower of the DRY principle - Don't Repeat Yourself

I don't claim credit for applying the term this way. Bruce Balmer sent the following email to the Rails mailing list...

I am breaking the DRY principle - could I avoid it?
I have two controller methods, new and edit.  They use the same form,
largely because they must.

I have the following code in both methods:

    @bb_tasks = BbTask.find(:all)
    @projects = Project.find(:all)
    @clients = Client.find(:all)
    @tasks = Task.find(:all)

The form needs those objects.  But I can't help feeling that I should
have another way to do this so I avoid aggravating the DRY police.
Far from the desiccated code I wish to write, I feel it is positively
soggy.

To which Rails core-team member Marcel Molina responded
Use a conditional before filter:

 before_filter :fetch_collections, :only => [:new, :edit]

 # ...

 private

   def fetch_collections
     @bb_tasks = BbTask.find(:all)
     @projects = Project.find(:all)
     @clients = Client.find(:all)
     @tasks = Task.find(:all)
   end

 marcel
Followed by the (IMO) priceless followup reply by Bruce, bold mine
Marcel:

You are a thing of beauty.  Thank you.  That is what I needed. I had
heard of before_filter but had not made the connection.

You are a desiccant, sir!

Read: Are you a Desiccant?

Topic: Rubyless Ruby Previous Topic   Next Topic Topic: Rails 1.0

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use