[Zope3-dev] Inline code

Casey Duncan casey at zope.com
Tue Feb 10 17:03:30 EST 2004


On Tue, 10 Feb 2004 14:04:05 -0500 (EST)
Shane Hathaway <shane at zope.com> wrote:

[..]
> 4. Drop ZPT and use scripts to do simple document transformation.  
> (Casey's suggestion.  Similar to XMLC.)
> 
>   -0

I'm not suggesting dropping ZPT. That'd be throwing the baby out with
the bath water. ZPT is far too entrenched an encumbent to just toss.
Many people like it (some emphatically ;^), and it is by all accounts a
huge success by many measures. Especially when measured against it's
predecessor.

IOW I don't expect my perfect world to suit everyone ;^)

I find ZPT has a "sweet spot" that you have to be careful to stay in. If
you can tilt the world correctly it usually just plunks in. It takes
some zen to get the tilt right, though, and sometimes you can't.

The three main places it breaks down for me is:

- Trying to read templates with huge define blocks, python expressions
and <tal:block> tags (which are never written by moi, heavens no ;^).
Regardless of whether they are "right" or not, ZPT makes it easy to do
it so people do.

- Modularizing things for maintainability or reuse though macros. This
quickly defeats many of its benefits and makes it hard to follow.
Especially where macros are parameterized or variable. Sometimes I feel
like I'm programming in BASIC (x = 1: y = 2: gosub 10250)

- Highly dynamic pages where the structure varies on multiple axis.
These quickly turn to mush in ZPT. The worst example I ever contrived
was an XML template where some element names were dynamic. It was
clearly outside of the range intented for ZPT and it smelled real bad.
Most are much less evil then that, but still mushy.

I think of the last one like inheritance versus composition. ZPT is like
an inheritance model where everything you do to the page is inside the
page. If you want to add a little thing here or there sometimes, you end
up adding lots of conditional code blocks every which way.
Transformation is more like composition. The things I do to make a page
can be spread out to different (hopefully simple) transformers that can
be mixed and matched. Adding an external editor pencil icon to the rows
in a folder view doesn't have to mean changing the folder view at all
directly. You just apply the transformer to do it. Maybe the same
transform (or a derived version) can also be applied to many other pages
too that show lists of items. Transformers also let you do global
changes in one broad stroke like: Change all <img> src attributes to
absolute urls, or insert standard <link> tags into the <head>, etc. 

Both ways have their place. Transformation is more abstract and
abstraction can be inconvenient and less transparent. ZPT's inline
notation is transparent assuming it is kept simple enough. OTOH the
potential for reusability in transforms (in a way like adapters) is
pretty compelling.

-Casey




More information about the Zope3-dev mailing list