[ZPT] Re: TAL's lack of an else...

Chris Withers chrisw at nipltd.com
Tue Aug 5 11:46:46 EDT 2003


Fergal Daly wrote:
> I presume you are not claiming that programming in XML is progress...

Templating to generate XML-ish type things (including HTML) needs to be done. 
TAL and METAL are the least painful way to do that I've seen so far.

> I am not propose anything with Evan. The first time I read the condition group 
> stuff I didn't get it. Now I get it and I can see some uses for it but I 
> think it's much too easy to make a mistake with it.

Indeed!

> What I was proposing was a way to do if/elsif/else, no more no less. I am 
> quite surprised to see people defending TAL's lack of else. 

I find the tal:define, tal:condition, tal:condition not: method quite 
satisfactory...

> isLoggedIn = user.isLoggedIn
> if isLoggedIn:
>   print "You are logged in"
> if not isLoggedIn:
>   hasCookie = user.hasCookie
>   if hasCookie:
>     print "Welcome back please log in"
>   if not hasCookie:
>     print "Please register"

Python is not a language used to egnerate XML-ish things. I don't thing 'else' 
realyl works there, and I don't see that making the syntax necessary to 'know 
TAL' even greater will help the majority of its users ;-)

>>Stuff used in this context should _never_ have side effects!
>>If it does, you deserve the complexity you get!
> 
> Whether due to side effects or expense, the most common practice seems to use 
> a temporary variable so template authors must be worried about something.

No, it just makes the code cleaner, you get the same in python...

average = (x+y+z)/3
if average < 0:
   print "eep!"
elif average > 0:
   print "yay!"

> I'm not familiar with them but I would guess wrapping all of your objects in 
> cache managers so that they can be used safely in your templates is not a 
> good idea.

It's not necessary, but it won't hurt things...

> Perhaps we should deprecate use of named variables and tal:condition and start 
> using registers, branch-if and gotos?

I think you should calm down before you reply next time ;-)

Chris




More information about the ZPT mailing list