velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Revusky <>
Subject Re: catching unbound methods?
Date Sun, 13 Oct 2002 18:49:57 GMT
On Sunday 13 October 2002 07:41 pm, Mark D. Anderson wrote:
> > i suggest you RTM (read the manuals) more carefully.  looking into the
> > code at and such is NOT the way to begin.
> I've read them til I'm blue in the face; they don't give any sort of
> precise description of how reflection is applied nor what happens when
> lookup fails.
> The point of my example was that "week" was misspelled as "weak".
> Thus
>    $calendar.getFirstDayOfWeak()
> is interpolated as an empty string (in my experience) with no warning at
> all. This makes templates very fragile. The person wanted:
>    $calendar.getFirstDayOfWeek()
> Thus typos in method names go undetected.

There has been an interesting debate recently on the Freemarker-devel list 
about this very subject. Earlier versions of FreeMarker (before 2.1) were 
very loose about undefined variables and, in fact, suffered from this exact 
problem, that if somebody misspelled a variable name, the template rendering 
machinery would just convert the variable into an empty string (or empty list 
or empty hash, case depending) and just keep chugging along as if nothing had 

I decided that, even at the cost of some transitional pain, we should move to 
stricter semantics and now (at least by default) references to undefined 
variables throw an exception. 

Interestingly enough, various people felt that the older semantics were 
better, and that it was better just to keep going (in the old way) when an 
error was encountered. Or, IOW, it was better to output an incomplete (or 
even incorrect) page than an error message. Well, that behavior can still be 
configured, but I cannot help but think that people preferred the legacy 
behavior (despite its dangerous implications) simply because it was... 
well.... the legacy behavior. They were used to it.

All of this has jogged my memory and it reminds me of an anecdote -- a very 
old anecdote, possibly apocryphal. I think this dates back to the 1980's when 
computer-generated form letters became a big thing.

A financial company had a list of what the financial industry calls "high 
net-worth individuals" (rich guys) to whom it sent a form letter pitching 
some investment scheme.

There was some bug in their templating mechanism and the letters were all sent 
out as something like:

Dear {rich_bastard}:

blah blah


Funny, though I suppose somebody did get fired.... :-(

What is striking to me is that this is the exact same scheme that Velocity 
uses. If, in your template, you have a variable exposed called, let's say 

and a template writer mistakenly writes:

$rich_bastard or even $richBastard

then apparently the template engine just passes it along as schmoo, as in:

Dear $rich_bastard

blah blah


Of course, since this is the scheme that Velocity has used for the past 2 
years, it must be the result of some careful though.

I suppose.... Well, at least the licensing issues are clear. The Apache 
license does specifically disclaim any responsibility for any damages 
etcetera resulting from use of the software... So at least the juridical 
angle is covered well... ;-)


Jonathan Revusky
FreeMarker-Velocity comparison doc
Velocity->FreeMarker template conversion utility

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

View raw message