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 15:01:01 GMT
At 9:26 AM -0500 11/4/02, bob mcwhirter wrote:
>Sorry for being pedantic here, but if you're calling a method and 
>ignore its return value in a template, then you're just wanting the 
>side-effects of the method call?  I'd consider that to probably be a 
>Bad Programming Practice.

Arguably so, but IMO it depends on the situation.  In the examples I gave...


     $myHashMap.put("name", "bob")


...I think it's reasonable to ignore the return values.  In these 
cases, the return values are provided as a redundant convenience -- 
for example, to chain append() messages -- not because their values 
absolutely must be dealt with.

In C (when I'm being meticulous), I explicitly cast function calls to 
(void) when I'm ignoring return values.  Can't do this in Java.   The 
nearest thing would be:

     ArrayList myArray = new ArrayList();
     boolean ignore;

     ignore = myArray.add("a");
     ignore = myArray.add("b");
     ignore = myArray.add("c");

But I don't like variables that are meant to be ignored.  A matter of 
taste, perhaps.

>Though, cheap and easy is to stick it inside HTML comments, if
>you're playing with HTML.  <!-- foo.getBar() -->.
>Velocity will ignore the HTML comment gleefully, and they'll
>prevent the return from being seen.

Another handy tip, thanks.


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

View raw message