Hello all,
I’m becoming concerned with the apparent loss of English-like DSL in Rails. When I first came to Rails as an experienced C++/C#/.NET engineer, I was thrilled to write code that felt more like English.
Specifically, the belongs_to and has_many methods introduced me to a mental model of coding that expanded my mind, and wielded the power of the Ruby language in a way that no other framework that I had ever seen.
Rails 3 brought a slow death to another area of wonderful DSL-ness: validations. Instead of this:
validates_presence_of :title
we’re now supposed to use the generic form:
validates :title, :presence => true
which to me is uglier and doesn’t read nearly as well. I understand the other argument: By using a generic #validates method, it brings apparent consistency to all of the other validation lines, and lets you combine options, etc. But I don’t like it because it sacrifices a higher cause, which is code intention and readability.
I still use the old validates_presence_of and will continue to until it’s forcibly removed.
Maybe most people like the new validates method, so I didn’t want to complain. But now I see that dynamic finders are going away too! As someone who spends most of my time helping newcomers to Rails, I think this is a bad decision.
There are few things nicer than learning that I can find my data with methods like:
Product.find_by_title(“iPad Mini”)
Product.find_all_by_rating(4)
My understanding is that in Rails 4, these go away! Replaced by a more generic version, that takes a hash for everything instead.
We are slowly replacing our English-like DSL with generic methods that mean nothing. Meaning has been moved into an ugly hash instead.
What next? Would you put up with:
class Category < ActiveRecord::Base
associated_to :product, :ordinality => :many
end
I hope not!
So if maybe it’s too late to save the validation methods, but I hope it’s not too late to save dynamic finders.
Who’s with me?
Thanks,
Jeff