Coding Guidelines: Instance variables in views

Matt Wagner matt.wagner at redhat.com
Fri Aug 17 13:59:15 UTC 2012


On Fri, Aug 17, 2012 at 02:12:28PM +0200, Imre Farkas wrote:
> These are quite reasonable arguments but personally I never felt it
> that problematic to avoid using them. Actually for me this is a neat
> feature of Ruby rather than an issue.
> 
> I think we should keep our coding standards in align with the
> standards of the Ruby and the Rails community. As Jirka wrote, there
> is no book on Rails that uses this approach, none of them matches
> with our coding guideline.

This got me curious, so I just looked it up.

The rubyonrails.org guides recommend using instance variables for views:
http://guides.rubyonrails.org/layouts_and_rendering.html

I'm not saying that we must take this as gospel, but I do think we need
to have a pretty compelling reason to do something differently than most
of the Rails community.

Of course, this is very different from blindly using instance variables
where they're not needed -- "users.each {|@x| puts "#{@x.name}"}" would
be absurd.

> As Matt linked from Rails Best Practices, they only recommend it for
> partials, not for all views as we specify. Our strict approach may
> frighten off future contributors, so I vote for not creating stricter
> coding standards than reasonable and let developers choose which
> approach they prefer.

+1 to this

In general, I actually think we should all agree on a "right way" versus
each using whichever approach we prefer. It seems like it would keep the
code more consistent and easier to follow. But at the same time, I'm not
sure that there's a huge amount to be gained by having an extended
debate over variables right now.

-- Matt



More information about the aeolus-devel mailing list