[ZPT] v2 of Path Prefixes in CVS

Fergal Daly fergal at esatclear.ie
Sun Aug 31 22:13:34 EDT 2003


First impression is it seems like an odd thing to have in TAL, that it would 
be much more natural to define the prefixes in your code, rather than in the 
template, otherwise you will have to define them in every template you use or 
start to make include templates which contain no markup but set up your 
commonly used prefixes. Is the scope global or local or can I say "global 
prefix blah".

It seems to be a backdoor for allowing arguments to be passed to method calls. 
Wouldn't it be easier to just allow passing arguments to methods without 
haing to define prefixes, then

<div tal:define="prefix my here/zptlib"
      tal:replace="foo/bar/my:complexscript">

could be just

<div tal:define="my here/zptlib"
      tal:replace="my/complexscript(foo/bar)">

which doesn't require lots of new syntax, could allow easily allow the passing 
of multiple arguments, whereas prefixes cannot and is exactly what everyone 
is used to already. Also, to me, it's much more readable.

I find the prefix expressions very confusing. When reading the one above I'm 
thinking foo, foo/bar, foo/bar/my, no, hold on, my has a ":" after it so 
forget about "foo/bar" for a minute, remember that my is here/zptlib, now 
call complexscript on here/zptlib with foo/bar as an argument. With simple 
arument passing I just mentally replace my with here/zptlib and everything 
else is exactly as before.

Until now, in TALES expressions the order of terms has always coincided with 
the order of terms in the equivalent python expression, so expressions were 
very easy to understand. Also "/" had a consistent meaning. It meant you were 
about to dig deeper into the tree of data, it meant that "foo/bar" must have 
some sort of key or method called "my" that we are about to access. However 
the "/" preceeding the "my" above doesn't mean that, it's just there as a 
separator. Unlike the other slashes, it does not imply any relation between 
"foo/bar" and "my".

If you're going to do it, it would be better to use a different character to 
separate "foo/bar" and "my", space for instance. That way I don't mentally 
try to do foo/bar/my and then have to backtrack when I realise "my" is a 
prefix, not a suffix. In fact I think that's an essential point, my is 
supposed to be a prefix but it's not prefixed to the things it operates on, 
it is actually infixed.

At the risk of waffling on for _far_ too long (as opposed to just _too_ long). 
":" changes the meaning of "my" so putting it afterwards is confusing. 
Compare

"hello ${user_name}, welcome to ${website_name}"

and

"hello {user_name}$, welcome to {website_name}$"

you don't know whether the "{" is going to be printed until you get to the 
end. The reason ":" works for prefixes like string: and not: is that they 
really are prefixes - they are at the start of an expression - and so you're 
not half way through thinking of one thing when you discover it's really 
something else,

F




More information about the ZPT mailing list