Topic: Rails Purity vs Efficiency
In my application I frequently come across the issue listed in the title.
Consider the following:
class Booking < ActiveRecord::Base
class Unavailability < ActiveRecord::Base
The difference between option1 and option2 is seemingly trivial. The readability seems just about the same('_' vs '.') The efficiency is the difference of a possible database query(depending if the booking object had previously cached the association). In practice, the addition of one extra query to the db could become significant if looping through thousands of Bookings. You might ask, why go at all with option2? Well, in my case, resource_id isn't just "resource_id" its a long drawn out name that makes the code harder to read. I feel "booking.resource.id" is certainly more "pure".
Another example is my colleague who loves doing raw sql queries as opposed to associations. His code is definitely more efficient(consider a query joining 3 tables vs. rails doing a query, getting the id, query again with that id, and so on...)
There are definitely criticisms on the way I'm doing the above code, but hopefully you'll see the point I'm trying to raise. If anything is unclear let me know. I'm interested in how and when people choose efficiency over rails purity.