[Zope] how to avoid REQUEST.set

Jens Vagelpohl jens@zope.com
Thu, 1 Nov 2001 08:34:13 -0500


seb,

the scenario you describe seems to introduce dependencies from one 
template to another that are only satisfied by explicit code in one 
template. this is one of the places where REQUEST.set is probably the only 
way.

i personally try to avoid dependencies like that, unless the dependency is 
on data that is available without the author's explicit intervention (e.g.
  stuff that is available through REQUEST, anyway). that's why i had not 
even thought about REQUEST.set in that situation.

have you thought about refactoring the code to break this dependency? if 
you have control over python code it is possible to move the test that 
gives you the variable you want to place into REQUEST into python and make 
it cheaper to do the test. then you can test in both places and thereby 
break the dependency.

jens




On Thursday, November 1, 2001, at 09:02 , seb bacon wrote:

> * Jens Vagelpohl <jens@zope.com> [011101 12:44]:
>> as far as the "REQUEST.set-sledgehammer" goes, most of its uses can be
>> replaced by dtml-let, which has the added advantage that you can look at
>> the code and see where a variable came from much faster than scanning all
>> code for REQUEST.set. maybe it's just me, but i consider REQUEST.set bad
>> style that should be used only if nothing else works.
>
> I dislike the 'set' hammer too, but there's one scenario in which it
> seems to be unavoidable: if you need to set a variable which must be
> accessed from several templates.  For example, I may have a
> navigation bar in one template, the colour of which I want to change
> depending on tests which take place in a content template.  Since
> <dtml-let> can't span more than one template, is there any other way
> of manipulating a global namespace in the context of a single
> request?
>
> seb
>
>> On Thursday, November 1, 2001, at 02:13 , Anthony Baxter wrote:
>>
>>> Like any site that's been around for a while, we've got a lot of
>>> DTML that shouldn't be DTML. We're gradually killing it, but
>>> we're looking at detecting stuff that _shouldn't_ be in DTML.
>>> One metric that's come up is "any DTML method that has 3 or more
>>> calls to REQUEST.set() is probably up to no good."
>>>
>>> Have other people found other useful rules of thumb about when
>>> to avoid DTML?
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )