Recent Updates

Rails 2.1 Eager Loading

As long as I can remember you could always eager load your associations in rails. If you wanted to find all your users companies, you could tell rails to do it in an efficient way.

There is no change in the code you write

User.all(:include => :company)

The SQL it used to generate was:

SELECT
  `users`.`id`      AS t0_r0
  `users`.`email   AS t0_r1
  . . .
FROM
  `users`
  LEFT OUTER JOIN `companies` ON `companies`.id = `users`.company_id

Fine, that isn’t really news, but now active_record splits that sql statement up into two statements.

SELECT * FROM `users`;
SELECT * FROM `companies` 
  WHERE `companies`.id IN ('1','2', . . . );

Apparently this will be faster in most cases. I don’t have anything to say about that but, there are two interesting things I want to show you. They both involve :conditions.

If you put conditions on the users table it still generates two queries.

User.all(:include => :company, 
  :conditions => "`users`.`email` LIKE '%gmail%'")
SELECT * FROM `users` 
  WHERE `users`.`email` LIKE '%gmail%';
SELECT * FROM `companies` 
  WHERE `companies`.id IN ('1','2', . . . );

But if you put conditions on the companies table it fails over to the old style and generates one statement

User.all(:include => :company, 
  :conditions => "`companies`.`name` LIKE '%google%'")
SELECT
  `users`.`id`      AS t0_r0
  `users`.`email   AS t0_r1
  . . .
FROM
  `users`
  LEFT OUTER JOIN `companies` ON `companies`.id = `users`.company_id
WHERE
  `companies`.`name` LIKE '%google%'

I don’t know if they have to do it that way to get the correct results or what. But I thought it was interesting.

Steve Yegge’s Google IO talk

Steve Yegge of Google gave the above talk, entitled “Server-side JavaScript (SSJS) on the Java VM.” It is long but great, I highly recommend it. It isn’t really about SSJS, although he did write a SSJS web framework called, “Rhino’s not Ruby” RnR. Which is a port of rails to JavaScript. Which makes him sound crazy, but he does have his reasons.

The talk is much more about dynamic languages and dynamic languages on the JVM. Even though I have no interest in the JVM anymore, he raises some great points. It is also a very funny talk, Steve keeps you engaged throughout.

The 3 Coolest things I saw at RailsConf

In no particular order

FiveRuns TuneUp

FiveRuns TuneUp

It is a tool for looking at what is make a request slow. The above screen shot shows the RideCharge landing page call stack.

Internally we hacked it so that it doesn’t run in development, but in a new environment development_tuneup. I also hacked it to ignore the idea of being logged in, to speed up adoption.

Passenger 2.0

I have long been a fan of mod_rails (now branded as passenger). There was a lot to be excited about in their talk. They talked about the release candidate features. But one of the most obvious (after you hear it) features was buffering file uploads. So, wait until the file is uploaded then dispatch to rails.

Pre Rails File Buffering

A Continued Commitment To Testing

The rails community has always been pretty committed to testing. It is our version of type safety. But, people are trying to do more and more testing in less and less time. There was a talk called “The Great Test Dance-Off” by Josh Susser. It was a pretty good summary of, Test::Unit vs. RSpec vs. Shoulda. David Chelimsky, RSpec Lead Developer, did a great write up on the talk. While I am a Shoulda man, I wholeheartedely agree with him that anything to get people testing and talking about testing is awesome.

RailsConf 08 ~ Day 2

RailsConf 08 day 2 was much better.

Jeremy Kemper gave the morning Keynote. It was about all the new shiny in rails 2.1, which is released today. He went over active_record scopes, migrations, time zones, and other things. I think the changes to migrations are brilliant and also painfully over due.

The first session I went to was on edge caching and ESI. It was given by Aaron Batalion. ESI is an alternative to fragment caching that is heavily used by akamai. I really liked this talk, it went at a good pace and the speaker was well informed.

The second session I went to was Advanced RESTful Rails by Ben Scofield. Unfortunately, my day job isn’t doing anything in a restful way. All that a side, I LOVED THIS TALK. I will definitely investigate how to start incorporating REST into my day to day.

The next session was Fast, Sexy, and Svelte: Our Kind of Rails Testing Dan Manges (ThoughtWorks), Zak Tamsen. They had some interesting ideas, and I really appreciate deep test. But, I don’t agree with unplugging your unit tests from the database which was one of their major points. I agree with their goals of making tests run faster and me more informative. I just don’t think the effort justifies the value. So, I will continue to have terrible average tests.

The next session was Integration Testing with RSpec’s Story Runner by David Chelimsky. I tried to go to a different talk, but I got there after the room filled up, so what I am about to say is as a person who didn’t want to go. RSpec Story Runner seems like an extreme pain in the ass. It is like why use one step when 100 will do. David was very well informed and well spoken, I like his style but not the content.

The last session, The Great Test Framework Dance-off by Josh Susser. I love his blog, and he is a great speaker with a very objective view point. And that is why he came to the conclusion that the best test framework is a matter of opinion. No surprises there!

And the Keynote by Kent Beck was a series of stories. About the “creation” of TDD, XP, and Design Patterns. It was very introspective and personal. He mentioned on several occasions the “watering down” of XP into “agile”. In his words, “who wouldn’t want to be agile”. I completely agree with that. The word agile is essentially meaningless. He came up with a new term, “responsible programming”. That basically refers to transparency and quality in the development process. I couldn’t agree more with the notion, but the phrase feels a little watered down (which I believe is the point.) So that makes an essentially good idea, 0 for 3 in naming in my opinion, extreme, agile and responsible.

I have so much respect for Kent Beck. He is a very humble and thoughtful person. I appreciated his talk more than anything at the conference. This is especially amazing considering it will have almost no practical impact on my day to day life.

About Simpltry

Simpltry is a weblog focusing on, but not limited to, web development. Both client-side and server-side topics are covered, with a focus on Rails, Javascript and CSS.

Feeds/Syndication