Jared's Weblog

Main Page - Books - Links - Resources - About - Contact Me - RSS


Jared Richardson Most Popular
Help! I've Inherited Legacy Code
Testing Untestable Code
Continuous Integration... Why Bother?
Mock Client Testing
The Art of Work
Technical Idiot Savants
Targetted Skills Aquition vs Free Range Chickens
The Habits of Highly Effective Developers



Blog Archive
2005-December
2005-November
2005-October
2005-September
2005-August
2005-July
2005-June

Thu, 23 Feb 2006

Ruby is so cool

I'm going through Dave and David's Rails book and parts of it just amaze me. How much code would it take in your language of choice to do the following:

  1. Pull all the data from a database table
  2. Filter out the data by some value on a single column
  3. Sort the data

Granted, this isn't rocket science. Any beginner programmer should be able to do this. But in the Rails book, it's four lines of code... and it could be one. It's written on four lines to be readable.

This is a routine that returns all the items that can be sold now. Can you read it?

def self.salable_items
   find (:all,
         :conditions  => "date_available <= now()",
         :order       => "date_available desc")
end	
I know, some of the magic is ActiveRecord, the Ruby OR layer... but in my mind I'm running through all the JDBC driver trappings, the selects, the sorting. Maybe if I'd tinkered with Hibernate, I'd know a four line way to do this in Java. Maybe....

Jared

posted at: 21:31 | path: | permanent link to this entry