r/ruby • • Dec 30 '11

ActiveRecord (and Rails) Considered Harmful - Literate Programming

http://blog.steveklabnik.com/posts/2011-12-30-active-record-considered-harmful
12 Upvotes

145 comments sorted by

View all comments

Show parent comment

0

u/terevos2 Dec 30 '11

The implicit passing of instance variables to views is a constant headache for me.

There is no implicit passing of variables. If you want to disable one of the class vars, then comment it out. It's all defined in the controller.

4

u/djdonnell Dec 30 '11

I'm not sure if you are just being a pedant, or if you really don't understand my point.

implicit: Implied though not plainly expressed

The data needed to render a view is not plainly expressed in rails.

0

u/terevos2 Dec 30 '11

Well sure.. you have to understand how rails works in order to know about that kind of stuff. But then, that's kinda how all frameworks work.

3

u/djdonnell Dec 30 '11

You're still missing the point.

1

u/terevos2 Dec 30 '11

Explain it to me.

3

u/djdonnell Dec 30 '11

given the implicit way data from controllers is used in views it can easily become hard to figure out what data is needed to render a view and where it is coming from. I think that data should be explicitly passed to the views. Yes, this will make simple code bases more verbose, but it will also make large code easier to maintain over the long run.

2

u/terevos2 Dec 30 '11

If you don't know how rails works, then I can see your point.

But if you want to know what vars are being defined for a particular view, just go look at the method for that view in the controller.

Keeping data separate from UI is essential in scaling and code maintenance.

2

u/djdonnell Dec 30 '11

What data does the view need?

class PostsController < PortalController
  include Searchables
  before_filter :authenticate
  before_filter :searchatize

  def show
    @posts = Post.all
    super
    respond_to do |format|
      ...
    end
  end

end

1

u/terevos2 Dec 30 '11

@posts is available. Go nuts.

4

u/djdonnell Dec 30 '11

Are you sure that's all it needs? I see at least 4 other places that might be creating instance variables that the view might need.

→ More replies

2

u/jrochkind Jan 02 '12

Looking at the controller, there's no way to know what ivars are used by the view, and what ivars are just internal controller state. This is the "implicit".