I have to say I am surprised by some of the comments I have received about
Canvas, and in particular from people who say that the Velocity Template
Language (VTL) is a better choice than Groovy because it’s not a "real"
language, so you are not tempted to mix presentation and business logic.

First of all, the assumption that the generated template is for
"presentation" (probably meaning:  a Web page) is a generalization. 
Velocity is used for much more than just generating Web pages, so this argument
is weak in my opinion.

But if you think the VTL is just a declarative language, you are fooling
yourself.  VTL has

  • Control structures (if, while, etc…).
  • Variables.
  • Macros.
  • And worst (or best) of all, it has access to the underlying Java

In other words, I am pretty sure that you can use VTL to write arbitrarily
complex pieces of code inside your template, and
Sam was quick to point out a

perfect example of that

With that in mind, if we are going to have to deal with a language inside the
template, I would rather use one that I like, is powerful and ideally, close to
the Java syntax.

There is also another reason why VTL is less than optimal for this, and it
has to do with the philosophy behind Velocity templates.

Velocity templates make no distinction between "verbatim text" and VTL. 
The only way to identify the pieces of VTL code in your template is by spotting
the various syntactic annotations (#, $, etc…).  The problem with this
approach is that it makes it pretty much impossible to guarantee the indentation
of the generated files, since you can never tell when a space is significant
(part or your "verbatim text") or should be ignored (used to indent a VTL

The JSP syntax (or any delimiter-based syntax) makes it obvious what spaces
should be preserved and which ones can be ignored for the generation of the
final file:

// Canvas template
public class GeneratedClass {
    for (i in methods) { i.generate() }

From my experience, it is absolutely impossible to get a decent indentation
for this very simple example with Velocity…