Jeff Cohen
2012-Nov-02 15:22 UTC
Argument against the slow removal of DSL features in Rails, like dynamic finders
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/-/BnVwXZKjTmcJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
DHH
2012-Nov-02 15:34 UTC
Re: Argument against the slow removal of DSL features in Rails, like dynamic finders
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". 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/-/87h9CEvATGoJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Jeff Cohen
2012-Nov-02 15:55 UTC
Re: Argument against the slow removal of DSL features in Rails, like dynamic finders
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 rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Deryl R. Doucette
2012-Nov-02 17:09 UTC
Re: Argument against the slow removal of DSL features in Rails, like dynamic finders
This is one of the big ticket items that drew me to Ruby (and to rails) in the first place. The expressive capabilities within your code using pre-established English-like DSLs. The loss of this aspect over time leaves me feeling rather sad. It feels as if Rails (and to some degree, Ruby itself) is moving towards a mind frame of terseness over expression. The ability to almost *talk* out the flow and type the exact things you just said and have it as workable code.. mmmmm. Delicious. I really hope that Rails does not move towards the idea that terseness is somehow better, that natural speech should not equal workable code, or drops the expressiveness currently inherent in the DSL. 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. > >-- 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/-/VvpzVCcm2Z4J. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Henrik N
2012-Nov-03 16:57 UTC
Re: Argument against the slow removal of DSL features in Rails, like dynamic finders
On Friday, November 2, 2012 4:22:38 PM UTC+1, Jeff Cohen wrote:> > 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 >My main issue with "validates" is that it''s easy to mix up with "validate" (http://apidock.com/rails/v3.2.8/ActiveModel/Validations/ClassMethods/validate). If you accidentally do "validate :title, presence: true", it will effectively do nothing, and won''t explode - it will call the "title" method and expect that method to add validation errors, and "presence: true" just becomes an ignored option. Tests will catch this, of course, but it''s still an easy mistake to make. I''m not sure what would be a good solution, though. Maybe complaining about unknown options? -- 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/-/FPthIt0hGf0J. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Matt Huggins
2012-Nov-04 13:30 UTC
Re: Argument against the slow removal of DSL features in Rails, like dynamic finders
> > If you accidentally do "validate :title, presence: true", it will > effectively do nothing, and won''t explode - it will call the "title" method > and expect that method to add validation errors, and "presence: true" just > becomes an ignored option.This is my biggest issue as well. Every time I start writing validations, I have to refer to old code to see which method is correct. On Saturday, November 3, 2012 12:57:26 PM UTC-4, Henrik N wrote:> > > On Friday, November 2, 2012 4:22:38 PM UTC+1, Jeff Cohen wrote: >> >> 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 >> > > My main issue with "validates" is that it''s easy to mix up with "validate" > ( > http://apidock.com/rails/v3.2.8/ActiveModel/Validations/ClassMethods/validate > ). > > If you accidentally do "validate :title, presence: true", it will > effectively do nothing, and won''t explode - it will call the "title" method > and expect that method to add validation errors, and "presence: true" just > becomes an ignored option. > > Tests will catch this, of course, but it''s still an easy mistake to make. > > I''m not sure what would be a good solution, though. Maybe complaining > about unknown options? >-- 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/-/0jgqNWUW5D4J. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Matt Huggins
2012-Nov-04 13:31 UTC
Re: Argument against the slow removal of DSL features in Rails, like dynamic finders
> > My main issue with "validates" is that it''s easy to mix up with "validate" > ( > http://apidock.com/rails/v3.2.8/ActiveModel/Validations/ClassMethods/validate > ).This is my biggest issue as well. Every time I start writing validations, I have to refer to old code to see which method is correct. On Saturday, November 3, 2012 12:57:26 PM UTC-4, Henrik N wrote:> > > On Friday, November 2, 2012 4:22:38 PM UTC+1, Jeff Cohen wrote: >> >> 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 >> > > My main issue with "validates" is that it''s easy to mix up with "validate" > ( > http://apidock.com/rails/v3.2.8/ActiveModel/Validations/ClassMethods/validate > ). > > If you accidentally do "validate :title, presence: true", it will > effectively do nothing, and won''t explode - it will call the "title" method > and expect that method to add validation errors, and "presence: true" just > becomes an ignored option. > > Tests will catch this, of course, but it''s still an easy mistake to make. > > I''m not sure what would be a good solution, though. Maybe complaining > about unknown options? >-- 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/-/hlgUGcTn0rwJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Gabriel Sobrinho
2012-Nov-05 21:10 UTC
Re: Argument against the slow removal of DSL features in Rails, like dynamic finders
I always do that too :( On Sunday, November 4, 2012 11:31:01 AM UTC-2, Matt Huggins wrote:> > My main issue with "validates" is that it''s easy to mix up with "validate" >> ( >> http://apidock.com/rails/v3.2.8/ActiveModel/Validations/ClassMethods/validate >> ). > > > This is my biggest issue as well. Every time I start writing validations, > I have to refer to old code to see which method is correct. > > > On Saturday, November 3, 2012 12:57:26 PM UTC-4, Henrik N wrote: >> >> >> On Friday, November 2, 2012 4:22:38 PM UTC+1, Jeff Cohen wrote: >>> >>> 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 >>> >> >> My main issue with "validates" is that it''s easy to mix up with >> "validate" ( >> http://apidock.com/rails/v3.2.8/ActiveModel/Validations/ClassMethods/validate >> ). >> >> If you accidentally do "validate :title, presence: true", it will >> effectively do nothing, and won''t explode - it will call the "title" method >> and expect that method to add validation errors, and "presence: true" just >> becomes an ignored option. >> >> Tests will catch this, of course, but it''s still an easy mistake to make. >> >> I''m not sure what would be a good solution, though. Maybe complaining >> about unknown options? >> >-- 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/-/UmTpdWGuw9gJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
mateo
2012-Nov-06 16:01 UTC
Re: Argument against the slow removal of DSL features in Rails, like dynamic finders
Same here... complaining about unknown options would help, but I''d also maybe suggest renaming "validate" to something like "validate_with", which I think would be even more readable... On Saturday, November 3, 2012 12:57:26 PM UTC-4, Henrik N wrote:> > > > My main issue with "validates" is that it''s easy to mix up with "validate" > ( > http://apidock.com/rails/v3.2.8/ActiveModel/Validations/ClassMethods/validate > ). > > If you accidentally do "validate :title, presence: true", it will > effectively do nothing, and won''t explode - it will call the "title" method > and expect that method to add validation errors, and "presence: true" just > becomes an ignored option. > > Tests will catch this, of course, but it''s still an easy mistake to make. > > I''m not sure what would be a good solution, though. Maybe complaining > about unknown options? >-- 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/-/2SglPpDaanYJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.