[stringtemplate-interest] v4 ST

Zenaan Harkness zen at freedbms.net
Wed Oct 7 16:35:32 PDT 2009


> >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);

I don't see why using .add here would cause confusion, or be a problem.
Add elements to an arraylist, add arraylist to ST. Sounds pretty simple
to me...

Whereas, with "inject" I say 'ok, I add elements to my list, now I want
to add the list to my STemplate.. what was that method name again?'


> // 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,

Ahh yes, .getAttribute. Well then, .putAttribute is the canonical
complement!

Symmetry demands .putAttribute as matching .getAttribute, if nothing
else. If there were .get, .put would be needed.

Simplicity/ ease of use, I say demands .add. About the only alternative
I could vote for is .put, as an abbreviation of .putAttribute, and I
imagine if we got into the debate, it might be hard to argue against
that. Notwithstanding, my feeling is that .add is more consistent with
the rest of the java api, as per List class demonstrated above.


> 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".

In the templates themselves, we see .getXXXAttribute type methods able
to be used, but no .putAttribute equivalents: method naming is
important, I agree, but there are various measures of software quality:

http://en.wikipedia.org/wiki/Software_quality#Software_Quality_Factors

I seem to remember reading, may be 15 years ago in a book (I think it
was Code Complete), that Consistency rates pretty high in importance,
due to flow-on effects, such as readability, usability, maintainability
and simplicity.

Minimising Cognitive Load for the user I feel is important, and to me,
.inject increases cognitive load, whereas .add reduces cognitive load.

best
zen

-- 
Homepage: www.SoulSound.net -- Free Australia: www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.


More information about the stringtemplate-interest mailing list