[Zope-dev] Re: TALES idea: tuple unpacking

Paul Winkler pw_lists@slinkp.com
Tue, 29 Jul 2003 18:05:36 -0400


On Tue, Jul 29, 2003 at 04:43:21PM -0400, Shane Hathaway wrote:
> Python expressions won't be banned.  I will never consider them 
> discouraged for all cases, either.  There will always be a need for 
> constructs like:
> 
> <div tal:condition="python: a == b">...</div>
> <div tal:condition="python: (a and b) or c">...</div>

ok.

> However, the following is quite bad:

And quite common :-)  Browse through some of the CMF skins...

>  <tal:x define="ss nocall:modules/Products/PythonScripts/standard">
>  <a tal:attributes="href python: ss.url_quote(some_url)" />
> </tal:x>
> 
> This is un-Pythonic in numerous ways.
> 
> - You can't use the import statement.  In fact, you can't use any 
> statements at all--only expressions.
>
> - The nocall: prefix.
>
> - The name 'modules' is present automatically along with many other 
> names that aren't in the Python builtins namespace.
>
> - Importing using a path expression.

agreed on all 4.  although, "import" is the only time I miss statements.

> - Binding a variable to a value without an equal sign.

That took some getting used to.  I don't know why this was
chosen, but it seems a bit late to change it now.

> - You have to prefix Python expressions with "python:".

That's a feature! If we didn't have that, how would you know the
difference between
   tal:replace="a/b" 
and
   tal:replace="python:a/b"

> Zope 2's method of slightly simplifying this is to write a two-line 
> script and find it through implicit acquisition.  The overhead of 
> invoking a script is somewhat large, but here's what the template would 
> look like anyway.
> 
> <a tal:attributes="href python: here.url_quote(some_url)" />

yes, this is about the best you can do currently. In fact,
I quite like it. :)  

> Zope 3 will not have implicit acquisition.  In fact, no system but Zope 
> 2 has implicit acquisition.  That leaves us with no possible way to 
> write the above statement in non-implicit Python!  No matter what you 
> do, you need some help from another kind of expression.  Until recently, 
> here was the way to write it in Zope 3.
> 
> <tal:x define="url_quote nocall:here/++acquire++url_quote">
>   <a tal:attributes="href python: url_quote(some_url)" />
> </tal:x>
> 
> That alternative is just as complicated and un-Pythonic as importing a 
> module in a template.  I can't think of a better way to write this given 
> the limitations of Zope 2 ZPT, without the giant implicit acquisition 
> band-aid.  Can you?
> 
> Zope 3's new alternative looks about like this:
> 
> <a tal:attributes="href here/format:url_quote" />

Where do you put the argument? I don't see some_url.

> To me, that's a vast improvment, and it's only one example.

It also raises some new questions that are about
on par with what would be needed to understand the zope 2 version: 
What kind of thingie is "format:"? Where can I find it if I want 
to learn what else it can do?  What do I do if I want 
format:some_custom_format?  How could I replace or augment
the format thingie and not break any template that uses it?

Not that it's bad to raise these questions ... I just want to point
out that the answers are far from self-evident.

> You know what was actually wrong with DTML?  The lack of Python Scripts. 
>  Without Python Scripts, everyone used DTML as a programming language. 
>  Once Python Scripts came around, DTML became a reasonable templating 
> language again.  If DTML used TALES expressions, it would be just as 
> clean as ZPT.

I think I just said this in another post :)

-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's MUZZY ANTIDISESTABLISHMENTARIANISTIC FJUKER!
(random hero from isometric.spaceninja.com)