[stringtemplate-interest] template expressiveness
Nate
misc at n4te.com
Thu May 10 17:24:38 PDT 2007
Terence Parr wrote:
>> B. Would index access to lists break separation? Eg...
>> $tests[0].name$
>> $tests[1].name$
>>
>
> yep because it is like calling a function with an argument from the
> template, not that there aren't similar things. Even referencing an
> attribute requires that I invoke toString, the difference is that
> there are no attributes or arguments going in.
>
>
>> [0] can be done with first(), but getting the nth element is
>> impossible otherwise.
>>
>
> on purpose I am afraid.
>
I disagree. Why is getting the first or last element any different than
getting the second? This is template logic and doesn't break separation.
IMO, it should be possible to index lists (stuff[1] and stuff[-1]) and
also to get sublists (stuff[2..5] and stuff[3..-2]).
It isn't like calling a function with an argument. It only pulls an
indexed value out of a list.
No matter how hard you try, you cannot make StringTemplate both useful
AND impossible to break separation. Instead I feel the goal should be to
provide a path for the user where they respect separation. Anything that
breaks separation should be an obvious misuse of the API, but it does
not necessarily have to be impossible. Enforcing separation certainly
should not reduce the expressiveness of my templates.
As I see ST now, it can do probably 70% of things well. 15% of things
are awkward and 15% of things are impossible without refactoring the
controller. ST lacks a lot of expressiveness and that really shows when
it is used for HTML. For example, alternating table rows in ST doesn't
work in the real world. Sure, in documentation you can show how
templates can be applied in a round-robin fashion, but this requires
duplicating the template that outputs the row. In a real application
this is probably not a simple template, and I certainly don't want to
copy and paste it just so I can alternate row colors!
-Nate
More information about the stringtemplate-interest
mailing list