On Friday, 2 November 2012 10:34:19 UTC-5, DHH wrote:
>
> Jeff, I agree that the old-style validation methods are better when you do
> not need to combine options. I'm +1 for keeping them around.
>
> But the new dynamic finders are just as good as before:
>
> Product.find_by title: "iPad Mini"
>
> is just as well as:
>
> Product.find_by_title "iPad Mini".
>
>
Ah! I must have misread a description, I thought it was going to be #find
with a hash.
Thanks for setting me straight,
Jeff
>
> On Friday, November 2, 2012 4:22:38 PM UTC+1, Jeff Cohen wrote:
>>
>> 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
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/9xTXdzpsvH8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.