[stringtemplate-interest] v4 ST

Gerald Rosenberg gerald at certiv.net
Wed Oct 7 11:20:19 PDT 2009


At 06:09 PM 10/6/2009, Graham Wideman wrote:
>At 10/6/2009 05:51 PM, Gerald Rosenberg wrote:
> >Have to say that I liked "inject" on first impression.  Add, set and
> >put all suggest that the data is potentially still accessible, as if
> >the template is just a list or map in the model.  Inject reflects the
> >conceptual separation: once injected, the template has control.
>
>OK, please correct my understanding if it's wrong:
>
>After the call to setAttribute/add/inject, in general the value that 
>the attribute points to *is* still accessible to the caller, *can* 
>still be changed, and is not actually "injected" into the final 
>string until toString is called.
>
>Actually I have to admit I'm unsure when setAttribute uses reference 
>semantics and when it uses copy, but at least sometimes it uses 
>reference, and in any case the values are not composed into the 
>final ST toString output until toString is called, as I understand it.
>
>If that's a correct account, then Gerald's discussion is really an 
>argument against "inject" I think, ...

Well, just to be clear on my thinking ;)

List b = new ArrayList();
b.add("Ter");
b.add("Graham");

// Inject (or whatever) is conceptually one way
ST.inject("names", b);

// Even though you can do this before calling toString(), it really
// isn't changing the established association of "names" with b.
b.add("Gerald");

Yes, I do realize that there is a convenience 
StringTemplate#getAttribute, but using that basically allows the view 
(or content generator) to act as a data store for the model.  While 
there may be practical reasons for having that method, it does blur 
the separation of concerns.  If getAttribute is changed to "get" (to 
parallel a change in setAttribute to add or put), will it tend to 
reinforce use of the view as a model data store?  The complement of 
"inject" might best be "read".



More information about the stringtemplate-interest mailing list