velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barbara Baughman <baugh...@utdallas.edu>
Subject Re: velocity macro #exit feature
Date Fri, 16 Jul 2004 14:55:24 GMT
I must say that I sure like having return in a programming language.
I would hate having a multitude of nested else statements until I'm
indenting past the middle of the line.

However, Velocity is written to be used by non-programmers.  Any macro
with logic that is that complicated should be handled by a programmer,
meaning it should be a tool rather than a macro.

So the programmer is in charge of providing the data and presentation
tools.  The designer takes care of the actual presentation with as
little 'programming' as possible.

Could this complicated macro be written as a tool?  I know I have some
tool methods that spout HTML code.  For example, the monthOptions
spouts all the <OPTION> statements for a <SELECT> that gives all the
months of the year and their values. The method monthOptions(int
month)  spouts all the <OPTION> statements with the given month
SELECTED.  This standardizes the HTML code with the java code I have
to process it.  This probably also breaks the MVC principle a bit,
since I'm technically messing with presentation code.  But it's more
like providing a complicated macro than deciding how to present the
information.

Barbara Baughman
X2157

On Fri, 16 Jul 2004, chenjian wrote:

> Hi,
>
> 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
> here.
>
> 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
> solutions.
>
> 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.
>
> Jian
>
> >===== Original Message From Carsten Heyl <cal@pixelboxx.de> =====
> >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
> >definition.
> >Think of a macro  as a template  with placeholders for the arguments.
> >Expanding the macro should'nt be much more than replacing the formal
> >arguments
> > 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
> >(http://www.stringtemplate.org/) and especially
> >* Enforcing Model-View Separation in Template Engines*
> ><http://www.cs.usfca.edu/%7Eparrt/papers/mvc.templates.pdf>.
> >(http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf)
> >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.
> >
> >
> >
> >chenjian@uvic.ca 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)
> >>#exit
> >>#end
> >>
> >>## 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,
> >>
> >>Jian
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>
> >>
> >>
> >
> >
> >--
> >  Carsten Heyl				cal@pixelboxx.de
> >  Pixelboxx GmbH			http://www.pixelboxx.de/
> >  Ostenhellweg 56-58			Tel.:   +49 231 53 46 30
> >D-44135 Dortmund
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


Mime
View raw message