[Zope-dev] ZPT and 'else'
Jeffrey P Shell
jeffrey@cuemedia.com
Fri, 10 May 2002 11:18:02 -0600
On 5/10/02 9:25 AM, "Marc Lindahl" <marc@bowery.com> wrote:
> on 5/10/02 12:47 AM, Jeffrey P Shell at jeffrey@cuemedia.com scrivened:
>
>>
>> You would need something to close off the 'if' statement, otherwise, a
>> document full of 'if' statements and no 'else' ones could fill up a stack
>> needlessly.
>
> What's so bad about that? The stack wouldn't carry over after <html></html>
> or <body></body> - couldn't practically more than 1000's - insignificant!
Still, yuck. It's - for better or worse - not a valid XML way. Even XSLT
does things like this:
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:choose>
<xsl:when test="system-property('xsl:version') >= 1.1">
<xsl:exciting-new-1.1-feature/>
</xsl:when>
<xsl:otherwise>
<html>
<head>
<title>XSLT 1.1 required</title>
</head>
<body>
<p>Sorry, this stylesheet requires XSLT 1.1.</p>
</body>
</html>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<xsl:if> can stand on its own, but to do the equivalent of else, one has to
use:
<xsl:choose>
<xsl:when test="expression">(template)</xsl:when>
<xsl:when test="expression">(template)</xsl:when>
<xsl:otherwise>(template)</xsl:when>
</xsl:choose>
But, Page Templates are not XSLT. And I thank gods for that. XSLT is
powerful, but I wouldn't be able to do the type of work I've been doing this
week with them as easily as I've been able to do them with Page Templates.
I couldn't even have done them as easily using DTML.
>> You would at the very least need something like:
>> <condition>
>> <if>...</if>
>> <elif>...</elif>
>> <else>...</else>
>> </condition>
>>
>> Which would ensure / cut back on needless growth of stacks and/or global
>> variables.
>>
>> Personally, I think the way Page Templates can do it (via a 'not'
>> expression) is fine. When I used it today (and in the past), I never felt
>> myself missing 'else', because there's not really an 'if' to begin with.
>> Just conditions. It keeps TAL light, and lets TALES take on the lifting of
>> how to write those conditions.
>
> Point is, it's slow and inefficient, and a clunky syntax. Reasons the whole
> idea of 'else' was invented in the first place. I worry, that ZPT is
> benchmarked 4x slower than DTML and it's becoming the standard - not a step
> forward. And issue like this haven't been satisfactorily resolved.
If speed mattered that much, we'd all still be using C and/or assembly
language. "Scripting Languages" have become very standard, even though
they're orders of magnitude slower than their compiled counterparts. I
don't think it would be any more worth turning Page Templates back into an
imperative programming language than it would be to turn Python into C. Or
Haskell into Python. Or J into Lisp. Or Zope into PHP. Every language
and platform has its strengths and weaknesses, and I think ZPT's strengths
more than make up for its current speed deficiencies. I spend less time
debugging and cleaning up Page Template code than I did with DTML,
particularly late-generation DTML. And the results look *much* better.
I personally can't see a way of having an else (or equivalent of
'xsl:choose') without starting to clutter up the current elegance of Page
Templates, and it has to do with the way Page Templates are designed (and
it's a design that I think is done pretty close to right). One reason being
that, since all TAL things happen on attributes (it is the 'Template
Attribute Language', and by law all XML attributes have to be quoted, you'd
end up with something like this:
<div tal:choose="">
<h1 tal:condition="some/expression">Yay!</h1>
<h1 class="warning" tal:otherwise="">Boo</h1>
</div>
The only way out of this is to introduce special TAL tags. And at that
point, we're back to some of the problems with DTML - 'special markup tags
and the editors the bruise them'. And at _that_ point, we're out of one of
the intended audiences of Page Templates.
> I think, if it's going to have logic in there, make it sufficiently powerful
> and efficient. Otherwise get rid of it altogether, unapologetically, and
> require Python for such things....
Another option is the XMLC route, which is painful. XMLC identified every
possible writable element with an id, and id only. Then, corresponding Java
code could refer to that ID and replace the element with something. It kept
the visual design side very clean, but the code to do the dynamic generation
could get very ugly.
Or, there's the option is to give up on templating altogether and go with
PHP style syntax, or fill up Python code with:
s += '<em>No contents available</em>'
I personally think Page Templates are rather elegant and a joy to use after
five and a half years of DTML usage. I keep having to deal with other
solutions like 'tea', 'cheetah', ASP/PSP, and it's just a mess.
--
Jeffrey P Shell
www.cuemedia.com