[stringtemplate-interest] Expressions in $if(...)$ statements.
Magdalin, Vlad
Vladimir_Magdalin at intuit.com
Fri May 15 16:39:41 PDT 2009
Thanks for the quick answers!
I'm glad to hear that some sort of simple Boolean operators might make
it into a subsequent release.
About the other point (arithmetic comparisons, etc), you are totally
right about the slippery slope, and it seems better to keep ST away from
going down that path.
Perhaps the only thing that would be useful when it comes to lists, is a
quick way to check the list contains only a single item, since I'm
finding this to be a common scenario in my views (e.g. plurality
wording, deciding to render as a single item or list). In my view, it
would fall into the same category as rest(), first(), last(), length(),
etc ... maybe something like single(). Just an idea ... for now, using
rest() works just fine for me, though I wonder about the overhead.
That brings up a side question: does rest() construct a new enumerable
object in the background via shallow copy and iterate over that, or does
it use the existing collection and iterates over it by skipping the
first item? Just curious.
Cheers,
Vlad
-----Original Message-----
From: Terence Parr [mailto:parrt at cs.usfca.edu]
Sent: Friday, May 15, 2009 10:14 AM
To: DVD
Cc: Magdalin, Vlad; stringtemplate-interest at antlr.org
Subject: Re: [stringtemplate-interest] Expressions in $if(...)$
statements.
Hi. Well, you've now just reinvented every other template engine. If
you don't want to enforce separation, you're free to use another
engine. Not sure why, after reading my papers, you've missed this
point. Every other engine says "we enforce separation" (well, except
JSP) and then first example inthe manual violates it. ST is unique
because I think anything worth doing is worth enforcing if possible.
Velocity just reinvented JSP but made us learn a new language; same
with the others...
Ter
On May 15, 2009, at 6:26 AM, DVD wrote:
> Pardon me if I am being repetitious for the simple expression
> evaluation option I brought up
> a few days ago. This "AND" needs is one of those simple expressions
> that could be
> resolved with a general purpose expression evaluation approach in
> stead of
> ad hoc resolution. I feel this can be achieved and with
> recommendation that author
> should refrain from using it unless model can not be modified to
> provide the property
>
> Terence Parr wrote:
>> On May 14, 2009, at 3:07 PM, Magdalin, Vlad wrote:
>>
>>
>>> Hi,
>>>
>>> I'm moving over from NVelocity to ST, and so far really liking
>>> the strict separation of concerns. However, there are two areas
>>> of functionality that are kind of in a gray area, and I'm
>>> wondering if ST supports them:
>>>
>>> 1. Boolean operators in if() statements, for example:
>>>
>>> $if(someBoolValue AND someOtherBoolValue)$ ...
>>> ...
>>> $endif$
>>>
>>> Is this possible?
>>>
>>
>> not currently...I have to do nested IF now, which is effectively
>> an AND...in new version of ST I think it will be alllowed.
>>
>>
>>> I'm finding myself putting together extra Boolean variables and
>>> passing them to the view data, but seems like this type of simple
>>> logic does not violate M/V/C separation purity any more than a
>>> one- value if statement does. I've found this post
(http://www.antlr.org/pipermail/stringtemplate-interest/2005-June/000055
.html
>>> ) from Terence, but can't seem to find if anything ever came of it.
>>>
>>
>> not yet ;)
>>
>>
>>> 2. Simple arithmetic operations that resolve to a boolean:
>>>
>>> $if(items.Count == 1)$
>>> ...
>>> $endif$
>>>
>>> Right now, I'm finding myself doing things like this to check if
>>> a list has one and only one item:
>>>
>>
>> You can do $if(rest(names))$ which asks if it has more than a
>> first item.
>>
>>
>>> This zoo contains $zebras.Count$ $if(rest(zebras))$ zebras $else$
>>> zebra $endif$
>>>
>>> I'm wondering if even simple logic like this doesn't belong in
>>> the view according to the ST methodology. Any help or insight
>>> is appreciated!
>>>
>>>
>>
>> It's a slippery slope. can't really allow logic in expressions
>> involving values.
>>
>> Ter
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>
>
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.329 / Virus Database: 270.12.31/2116 - Release Date:
05/15/09 06:16:00
More information about the stringtemplate-interest
mailing list