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

Fergal Daly fergal at esatclear.ie
Wed Aug 6 17:25:27 EDT 2003


On Tuesday 05 August 2003 10:46, Chris Withers wrote:
> 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.

That's fair enough but I don't consider these to be programming except in the 
most general sense, TAL is not capable of simulating a Turing machine. I 
meant that general programming in XML is not progress, it's far too verbose 
for human comfort.

> > 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...

This is where we differ. I don't find it satisfactory, anything that makes me 
type the same thing twice, I consider bad and in need of elimination if 
possible. Having to type the same thing twice leads to errors. Repetition is 
what computers are good at and what humans are bad at.

> 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 ;-)

This is what puzzles me (and it's not just you by the way) in one paragraph 
people say "you don't need else for generating XML" but then in another 
paragraph they say "even though I _never_ need it, I just use tal:define and 
and not:". People seem to have very fixed ideas about how to do something 
that never needs to be done ;-)

Actually, TALES has a form of if/elif/else using the "|" syntax and it's 
widely used, so if anyone believes that if/elif/else is an advanced 
programming concept that has no place in a template language, they should 
rewrite any templates that use alternation in their expressions.

> 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!"

Except you forgot the case where average == 0. Assuming you do want to react 
to that, you need to add

elif average = 0
  print "hmm"

which is probably better written as either

else
  print "hmm"

or if the if/elif sequence is more complicated and had say lots of elifs for 
different ranges of the average

elif average = 0
  print "hmm"
else
  print "WTF? average was ${average} and I missed it"

> > 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 ;-)

I would have said turing machines but I only thought of it after I pressed 
send.

Fundamentally I have two questions:

1 would a if/else be useful in TAL? I think so and judging by some of the code 
I've seen people are doing it anyway, so I can't understand what the 
objection in principle is and as I pointed out TALES has a specific form of 
if/elif/else using the "|" syntax, so it is clearly a useful concept even in 
a template language.

2 is it possible to do it nicely in TAL? This is the question I'd really like 
to have answered. As I've said before, none of the suggestions have been very 
nice. Does that mean there isn't a nice way?

Unfortunately most of the debate has been about Q1

F




More information about the ZPT mailing list