On Fri, 2008-12-05 at 13:12 -0800, Bluebit wrote:
> Hey,
> I was wondering if there was any disadvantages using locals() when
> calling render_to_response().

One aspect that is relevant as your codebases grow and you work in
larger teams, is that it's kind of a lazy, messy coding practice. It
becomes time consuming to work out what parameters are actually being
passed around. Particularly when some parameters might be optional (the
direct relevance to Django templates noted below). If somebody uses a
new variable in a function that passes locals() onto something else,
they have to think about whether that name might actually *mean*
something to the receiver.

With respect to templates, if you are using other people's templates, or
even as you write some more advanced ones of your own, you'll find that
it's often neat (in the "leads to clean layout" sense, not the "cool,
dude" sense) to not necessarily require all variables to be present. For
example, on my blog, I insert RSS feeds if they exist in a particular
context variable. If the variable isn't present, I just move on. Now
imagine if I used the locals() approach -- I would have to always
remember never to use that variable name as a local variable, since it
would lead to unexpected results. Now expand that restriction to every
variable you use in every template.

The locals() idiom works nicely for small amounts of code and maybe
throwaway fragments. Personally, if I had one of my team manager or code
reviewer hats one, I'd consider it a bug. But if it solves your problem
and you go into it with your eyes open, knowing what the downsides might
be, that's a reasonable decision to make.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to