[Zope] My Way of Zope Programming

Jens Vagelpohl jens@zope.com
Thu, 8 Aug 2002 07:57:25 -0400


>  Example:
>   def foo(self, REQUEST):
>       "docstring"
>       ....
>       ret=[]
>       ret.append(self.root.standard_html_header())
>       ret.append("""
>            <your tag>
>             %s
>             <foo>%s</foo>
>            </your_tag>
>              ....
>            """ % (var1, var2))
>       return string.join(ret)
>

now that's horrible.

hardcoding HTML into python is a maintenance nightmare. i suppose it's OK 
if you are the one who will be maintaining that code until it dies from 
bit-rot, but i would pity anyone else who did not write it and who has to 
maintain it somehow ;)

one of the goals of zope (and especially ZPT now) is to keep presentation 
and logic apart. IMHO that's a great goal.

one of the patterns that has evolved on "the other side of the fence" 
(meaning at zope corp), so to speak, is a "three-tier" way of coding:

- python products handle all logic. they do not know about web stuff like 
REQUEST

- python scripts are used to glue the web-unaware python product to the web

- ZPT does the presentation. all the templates should ever talk to is 
those glue python scripts

there are quite a few advantages to this:

- design can be done independent from logic development. adding more logic 
or changing logic has no influence on the design anymore

- web-unaware python products are easier to test using unit tests because 
you don't have to fake out certain things (such as web requests) in your 
test environment anymore. the code is cleaner, smaller and more efficient.
  and, IMHO, more understandable.

etc...

jens