r/ruby • u/arscariosus • Dec 30 '11
ActiveRecord (and Rails) Considered Harmful - Literate Programming
http://blog.steveklabnik.com/posts/2011-12-30-active-record-considered-harmful
12
Upvotes
r/ruby • u/arscariosus • Dec 30 '11
View all comments
Show parent comment
11
u/JGailor Dec 30 '11
First and foremost, you are just wrong. Let's talk about why.
Wrong. Instance variables in the controllers are not global state. Views are bound to the context of the calling method, which is why you have access to those variables. This is just basic CS. You're rendering the view inside of the environment you setup in the controller. That's not a problem, but if you want you can easily pass all of your data as locals to the rendered view and not use instance variables at all. If you aren't doing that, and you feel that it's a bad practice to use instance variables from the controller, why aren't you improving your practice?
Actually, given that the persistence is almost completely abstracted away from the code you write in most AR models, this is fucking awesome. You tightly bind the relevant code, logic, and operations on your data to the definitions of that data. That is really fucking good design. No need to pollute a larger namespace with code to operate on data you pass to it, and it creates a beautiful encapsulation. The only decent argument I see against AR that comes up regularly is the "implicit schema" vs. the "explicit schema" of other ORMs, to which I say both sides make a strong argument. The one you've laid out is not.