velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Lee <>
Subject RE: discarding method return values
Date Mon, 04 Nov 2002 21:34:29 GMT
At 2:28 PM -0500 11/4/02, Kevin Baynes wrote:
>Let me clarify: my question is "Why hardcode an array *in the 
>Velocity Template*?".

Good, I figured that was really the more interesting question to you, 
so I'm glad we got the other stuff out of the way.

I'm going to assume you are not opposed to the very existence of 
array literals.  The question seems to be, what should and shouldn't 
be coded into array literals?

Unless new information comes to light (like "They're planning to add 
multi-line array literals to Velocity!"), I am going to stand by my 
argument that *if* you have a long array in your template, there are 
good reasons to break it up into add() messages on multiple lines. 
And that would be one example of calling a method in a template whose 
return value you don't want to display.

>All your looping examples are perfectly correct, my focus is on what 
>level you acquire the data and make decisions on it.

It depends what you call "data."  I think it also depends on the 
requirements and design of your application.  At some point, 
"cleanness" becomes "over-engineering."

>It seems cleaner to store data externally, in a properties file, in 
>an XML file, in a database. I use XML files for this purpose, they 
>are easy to read and change. I don't want any data hard-coded in my 

I don't think I'd make the statement so broadly.  For any given app, 
there are judgment calls to be made.  After all, at some level, 
*everything* in the template is "data."

Suppose you are writing a calendar application that needs to be 
internationalized.  If your design uses one central template for all 
languages, then there should probably be Controller code to provide 
the template with appropriate names for the months of the year.

*But* if your design uses a separate template for each country, and 
the selection of the template itself is made by the Controller, then 
I think it's okay to hard-code the month names into the template (or 
put them in them in their own template to be #parsed).  I think 
creating a separate XML file or database table for this would be 

Another example.  Suppose I have a Web page that lists my top 10 
favorite stocks.  Say this is a purely subjective thing; every day I 
edit the list by hand, based on gut feel and brib^H^H^H^H reports 
from publicly traded companies.  I think it makes sense to have an 
array at the top of my template like this (ignoring the fact that 
this will print "true" ten times):

#set( $myFaves = [] )
## etc.

There's no advantage to putting this list in an XML file or database table.

*But* if I suddenly become the Martha Stewart of stock advice and my 
"top 10" list is used in 137 worldwide media applications, then for 
this Web page it makes sense to have the Controller get the list from 
a central place and feed it to the template via the Velocity context.

*Or*, alternatively, my little .vm file could *be* the central place 
everybody else gets the list from, in which case I'm back to 
hand-editing the file again.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message