velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph.R...@dlr.de
Subject Re: discarding method return values
Date Tue, 05 Nov 2002 12:17:16 GMT
Hi Andy,

I cas see some uses of velocity apart from MVC where you would
code values into a template... but that is another issue (where
a multi line set comes handy).

You example below just shows that you want to explicetaly call
the add method. OTOH the template processor does not know that
and thinks you want to display the result of that method call.
That is why I have stated previously in this thread that in such
cases you should do the call explicetely:
#macro( call $foo )#if( $foo )#**##end#end
## I used an empty copmment in the if-body since an earlyer version
## of velocity coughed when the #end directly followed the #if()
...
#set( $myLongWords = [] )
#call( $myLongWords.add("rhinoceros") )
...

You could even create an #add macro
   #macro( add $array $value )#if( $array.add( $value ) )#**##end#end
and do
   #add( $myLongWords "rhinoceros" )
That is the nice thing about macros...

Cheers,
Christoph

Andy Lee wrote:
> At 10:16 AM -0500 11/4/02, Kevin Baynes wrote:
[snip]
> #set( $myLongWords = [] )
> $myLongWords.add("rhinoceros")
> $myLongWords.add("callipygian")
> $myLongWords.add("lactovegetarian")
> $myLongWords.add("dodecahedron")
> $myLongWords.add("subliminable")    ## political humor
> $myLongWords.add("Schwarzenegger")
> $myLongWords.add("0xDEADBEEF")      ## geek humor
> 
> 
> Easier to read, easier to reorder, easier to comment items out.  And 
> notice that you can comment individual items in a readable way.
> 
> But I don't mean to focus on hard-coding as the issue.  The issue is 
> calling non-getter methods at all.  Regardless of hard-coding, *any* 
> call to ArrayList.add(Object) or HashMap.put(Object,Object) has a return 
> value, and I almost never want to display it.
> 
> One could decide as a matter of policy to only call getter methods in 
> templates.  I would find this needlessly restrictive.
> 
> --Andy

-- 
:) Christoph Reck


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message