[LRUG] Proffer and introducing constraints to Rails

James Hunt ohthatjames at gmail.com
Mon Apr 2 08:05:04 PDT 2012


How much more convenient is it though? How much time do you really save by
having instance variables by default? It's interesting to think about this
the other way: if Rails had never exposed instance variables by default,
would you even miss it? Would you have written a gem to add the
functionality? How would you justify it?

In the scheme of all the things you have to do to get a Rails app working,
not having instance variables in views seems like a really small thing. And
if you were reaaaaallly desperate, you could do:

<% @post = post %>

at the top of your view and you're back in business! The only difference
here is that before you do something like the above, you have to actually
think about what you're doing and why before you do it. It's a convention:
break it if you want, but know why you're doing it and what it may cost you
later on.

James

On Mon, Apr 2, 2012 at 2:43 PM, Ed James (Alt) <ed.james.spam at gmail.com>wrote:

>  Further to Andy's comment, we also need to remember that many Rails apps
> start off as prototypes. The prototypes that work quite often make it to a
> version release, which doesn't always allow for much refactoring. Stuff has
> to get done quickly and this is what makes Andy's "instant access"
> valuable. It can also be quite cumbersome to have too many strict rules
> (and even tests!) when the requirements are in a constant state of flux,
> which is common in early development stages.
>
> --
> Ed James
> Sent with Sparrow <http://www.sparrowmailapp.com/?sig>
>
> On Monday, 2 April 2012 at 11:42, Andrew Stewart wrote:
>
>
> On 2 Apr 2012, at 12:20, Viktor Tron wrote:
>
> I don't know who came up with this pattern in rails in the first place, it
> violates everything you ever wanted objects and instance variables to mean.
>
>
> True, but you have to admit it's tremendously convenient ;)
>
> I know it's heretical to say so but I like being able to access instance
> variables as if by magic in my views. I came to Rails from J2EE / JSP /
> servlets where accessing controller data in views was outstandingly
> tedious. I know Rails' approach violates encapsulation and so on...but I
> like it.
>
> Cheers,
>
> Andy Stewart
> ----
> http://airbladesoftware.com
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120402/ae677cbb/attachment-0003.html>


More information about the Chat mailing list