velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenjian <>
Subject velocity macro #exit feature
Date Fri, 16 Jul 2004 14:19:43 GMT

I have some counter views about not adding #return to the macro.

1) Most developers are familar with return statement in any programming 
language, and the most intuitive solution is to provide a #return.

2) Talking about macro logic, it reminds me about the story for "doing the 
right thing". For any of you who haven't heard about it, the short story is 

The MIT guys built their AI operating system based on their philosophy that 
one should do the right thing. The New Jersey guys built the C/Unix operating 
system based on more pratical and simple solution. The result turned out that 
C/UNIX won because it adapted to good software engineering practice. The "do 
the right thing" MIT guys built an operating system that is hard to use, and 
too complicated.

So, the moral of the story here is that we should follow good software 
engineering practice in our design. We are building software systems that are 
used by normal users. And typically, normal users don't like convoluted 

To summarize, I don't see why a simple #return will ruin the whole beauty of 
the template engine. Because simply by using template engine, we already 
restricted using Java directly in the presentation layer.


>===== Original Message From Carsten Heyl <> =====
>My $0.02 to the velocity maintainers:
>Please don't add something like this to the velocity standard code.
>Velocity has two major strengths:
>    1. it's a "macro language", thats means "replacing text"
>    2. it's simple
>"return" oder "exit" is a control flow statement from procedural
>programming and does not belong in a macro language inside a macro
>Think of a macro  as a template  with placeholders for the arguments.
>Expanding the macro should'nt be much more than replacing the formal
> with actual parameters. That's not totally true for velocity because of
>it's parameter evaluation but IMHO that's tolerable.
>"return" or "exit" would totally break this model  and open up the way
>to more control flow decisions in velocity which leads to jsp, php, etc.
>Please keep velocity simple!
>There are alternatives for the "special case" shown by others on the list.
>IMHO velocity templates come to it's best using some simple loops
>and some boolean flags, complex case decisions are done in java code and
>velocity just enables/disables template parts.
>Avoiding "#else" is a good thing. Name your cases and include code based
>on these cases.
>Before trying to "improve" velocity please make yourself familiar with
>template languages.
>I strongly recommend a look a stringtemplate
>( and especially
>* Enforcing Model-View Separation in Template Engines*
>for a classification of template languages and consequences.
>Both are written by Terence Parr, the author of LL-Grammars and ANTLR, a
>man who definitely knows grammars and
>programming languages.
> wrote:
>>Hi, All,
>>This question is similar to the one for adding a #exit to velocity
>>template, but, I think maybe more difficult to add this feature. Anyway,
>>here is my problem.
>>I am writing a macro and I want to do something like:
>>## check for a special case
>>#if (false)
>>## general cases, do processing
>>Without the #exit feature in the macro, I have to do put all my general
>>cases into a #else statement, which is a lot of indenting, since in the
>>general cases, there are also lot of if else statements.
>>Is it very easy to add the exit feature to velocity macro and could anyone
>>let me know how to do it?
>>Thanks a lot,
>>To unsubscribe, e-mail:
>>For additional commands, e-mail:
>  Carsten Heyl
>  Pixelboxx GmbH
>  Ostenhellweg 56-58			Tel.:   +49 231 53 46 30
>D-44135 Dortmund
>To unsubscribe, e-mail:
>For additional commands, e-mail:

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

View raw message