[Templates] tt annoyances

Andy Wardley abw@andywardley.com
Fri, 10 Oct 2003 13:34:13 +0100


Mark D. Anderson wrote:
> Keep in mind this is with the best of intentions; 

Understood.  For what it's worth, your critiscism is both constructive
and fair, and I'm glad that you took the time to do it.

> 2. There is no "typeof" or "instanceof" operator (or similar).
> Perl has "ref" and "isa"; practically all real programming languages

Yep, in TT3 there will be both 'ref' and 'type' vmethods for all types.
The .ref vmethod returns what Perl's ref() returns so for cgi_obj.ref
it will return 'CGI' but for text.ref it will return nothing.  The 
.type vmethod will be slightly different, returning 'TEXT' for text.type 
and 'OBJECT' for cgi_obj.type, for example.

> 3. There is (effectively) no "defined" operator.

Nope.  That was intentional.  But it should (in theory, if not currently
in practice) to be able to set your own variable called 'undef' which 
has the Perl undefined value and then use it.

The current stash doesn't handle undefined values very well.  This is
definately something that I plan to improve...

> I refuse to run without undefined variable warnings (in TT, that
> means DEBUG=undef). 

...this too.

> 4. Common string functions are available in counter-intuitive ways.

This is all sorted in the new TT3 virtual methods.  Vmethods, filters
and things like the String.* functions will all become one.

> 5. The iterator objects/methods are not generic.

Yep, this also needs to be fixed.

> 6. You can't call methods directly on literals, for example
> [% 'asdf'.length %] or [% [1,3,2].sort %].

Yes, this is already implemented in the new TT3 parser.

> Certain common operators such as [% count++ %] and [% count += 1 %]

Ditto.

> All these and others are of course a concomitant penalty for going with
> the mini-language school of template systems ("We're hurting you
> because we love you"...). Still, it hurts.

I'm here to take the pain away  :-)

> 7. There is no way to comment out a whole block of template lines which 
> includes
> other directives. That is, you can't nest things like [%# [% %] %].

True, but that's a limitation of the scanner/parser and it's very 
hard to work around that.  The scanner has no way of knowing which 
'%]' terminates the directive.

Nevertheless, it is something that I think I've managed to work around 
in TT3.  Well, to a fashion.  You may have to use a different tag style, e.g. 

  [# [% ... %] #] 

Or it may be possible to do something like this:

  [%# [% ... %] #%]

Or
  [% COMMENT %]
     [% ... %]
  [% END %]

Maybe.  Whatever.

> 8. A bug: [% SET str = 'a'; str.repeat(0) %] prints 'a', not ''

Now fixed.

> 9. The diagnostics stink. (This was a topic of an earlier email post.)

Yep.  Again, I'm working on that.

> 10. Boolean interpolation is non-obvious. [%1==2%] interpolates
> as '', and [%2==2%] interpolates as '1'. 

Blame Perl for that one.

> There are also no builtin constant values true and false.

But it's not hard to write:
  [% true  = 1
     false = 0
  %]

I prefer that to adding more reserved words.

A