Coding Guidelines: Instance variables in views

Imre Farkas ifarkas at redhat.com
Thu Aug 23 15:06:35 UTC 2012


On 08/21/2012 03:32 PM, Jirka Tomasek wrote:
> On 08/21/2012 07:36 AM, Mo Morsi wrote:
>> On 08/17/2012 05:12 PM, David Lutterkort wrote:
>>> On Thu, 2012-08-16 at 11:05 -0400, Matt Wagner wrote:
>>>> Hi folks,
>>>>
>>>> I've noticed that we've been objecting to patches using instance
>>>> variables to pass information to views, so I went to see our coding
>>>> guidelines page[1] to read about why.
>>>>
>>>> It makes very clear that it's bad, but it doesn't really explain the
>>>> right way. I'd hoped that the Coding Guidelines page would be more of a
>>>> guide on how to do things the right way.
>>>>
>>>> I've really only found one blog post[2] that addresses the issue,
>>>> and it
>>>> doesn't really give a great example. It still uses an instance variable
>>>> in the controller, but inside of a view it passes it as a local
>>>> variable. It's more specific, sure, but it's not abundantly clear how
>>>> that actually makes anything better, or why an instance variable from
>>>> the controller to the view is okay but a view to a partial is not okay.
>>> I've seen that statement in the coding guidelines, and have simply been
>>> mystified by it. It seems to take a reasonable rule (reusable partials
>>> shouldn't rely on instance variables) to an absurd extreme (never use
>>> instance variables to pass data to a view)
>>>
>>> The dividing line should be whether a particular view/partial is
>>> reusable, or meant to be reusable. As long as a view is only used from
>>> one place, I don't see anything wrong with using instance variables.
>>> Note that that doesn't mean partials should never use instance variables
>>> - there's more reasons than reuse to split part of a view into a partial
>>> (AJAX updates, for example)
>>>
>>> David
>>>
>> +1. Would be in favour of rewording the code guidelines to take this
>> approach.
>>
>>    -Mo
> +1
>
> Jirka

Updated the wiki page, you can check it out:
https://www.aeolusproject.org/redmine/projects/aeolus/wiki/Coding_Guidelines

Imre




More information about the aeolus-devel mailing list