[stringtemplate-interest] Attribute not found exception?
Koen Van Exem
koen at allors.com
Thu Mar 30 22:59:43 PST 2006
Because StringTemplate doesn't have some sort of Exception handling
(what I think is not necessary anyway) it has to decide what to do in
'exceptional' circumstances.
As Jon Postel puts it nicely: "Be conservative in what you do, be
liberal in what you accept from others"
This is probably the right behavior for an HTML template, where you
don't want
to send an "500 Server not available" error to your visitors just
because the 'messageOfTheDay'
attribute was not sent to the template.
On the other side of the spectrum the principle of "Fail Safe and Fail
Early" stipulates
that as soon as we find an error we should halt.
This is probably the right behavior for code generators and all other
stuff that's being
done at 'development' time.
So, I think there should be a "Lenient mode" and a "Strict mode".
Currently StringTemplate is a bit of both on this topic, it is Lenient
because
it evaluates missing attributes to the empty string, but it throws an
exception
when it can not evaluate a property on an attribute.
This is actually a breach against principle 4 "The view cannot make data
type assumptions".
(OK, maybe a bit far fetched, but the view is throwing an exception
because of a Type error ...)
So the FULL Lenient mode should probably evaluate missing properties on
objects
as empty strings too.
So to summarize, there should probably be 3 modes:
1. default mode (attribute lenient and property strict)
2. lenient (attribute and property lenient)
3 strict (attribute and property strict)
Koen
PS: An on topic blog posting at
http://blog.hibernate.org/cgi-bin/blosxom.cgi/2006/02/03#a_story_about_freemarker_and_velocity
Jeremy Gray wrote:
> To chime in with my company's perspective:
>
> We would very much like to be able to set all sorts of attributes that
> may or may not be used in the various templates that can be applied, so
> any checks and balances can't really be applied from that end, at least
> not in the sense of "setRequiredAttribute" and the like.
>
> That said, on some occasions it can be useful to determine whether or
> not a template is referring to an unpopulated attribute, especially on
> an automated basis.
>
> With the above in mind, I'm wondering if the thread starter's needs
> might be met, at least in part, through the addition of a feature that
> would allow for programmatic control over the value to be output when an
> attribute cannot be resolved. Under normal operations this would
> continue to be an empty string. Under automated testing, for example,
> this could be changed to something arbitrary that would never otherwise
> appear in normal output (eg. !!!MISSING_ATTRIBUTE!!!). A testing
> process, human or otherwise, could then detect such output with relative
> ease.
>
> Jeremy Gray
>
> -----Original Message-----
> From: stringtemplate-interest-bounces at antlr.org
> [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Terence
> Parr
> Sent: Tuesday, March 28, 2006 1:15 PM
> To: StringTemplate
> Subject: Re: [stringtemplate-interest] Attribute not found exception?
>
>
> On Mar 28, 2006, at 12:59 PM, David Moshal wrote:
>
>
>> Ter - I think the question was a little different. In actual use,
>> the system doesn't complain if you set an attribute which
>> doesn't exist, which becomes very hard to debug. One needs to look
>> at the generated code.
>>
>
> Oh! Right, Yes, that is a very big problem! You are right. the
> problem is, how do you know what the complete set of attributes is?
>
> Ter
>
>
>> Dave
>>
>>
>> On 3/28/06, Terence Parr <parrt at cs.usfca.edu> wrote:
>> On Mar 28, 2006, at 11:00 AM, David Moshal wrote:
>>
>>
>>> I too have thought this might be useful at times, and was wondering
>>> if the api could be extended to support this,
>>> ie:
>>>
>>> setRequiredAttribute (...);
>>>
>> Sometimes you want it and sometimes you don't in same app. You want
>> attributes with no value to be blank w/o an IF:
>>
>> $if(foo)$foo$endif$
>>
>> Ter
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>>
>>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
More information about the stringtemplate-interest
mailing list