You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Lev Epshteyn <le...@corsis.com> on 2001/12/11 17:06:19 UTC

So much syntax...

Hi...

I'm kinda new to Velocity, (coming over from freemarker because i couldn't
afford to write wrapper classes for everything from scratch at my new job)
and I have a question about all the syntax variants of variable inclusion
that velocity has.

What is the purpose of having so many:

$foo
$!foo
${foo}
$!{foo}

I mean understand how they are different, but for my purposes I do not want
to explain the difference to the designer, who I will probably ask to always
use $!{foo} because it is the most error-proof one, even though I think it
looks awkward. I understand the shorthand reason for allowing $foo to be
used, but are the two "saved" characters worth the confusion? Are there
situation where you WANT to use $foo instead of $!foo? (I mean why would you
want the variable to show up other than for debug purposes?)

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: So much syntax...

Posted by Nick Bauman <ni...@cortexity.com>.
For that matter to have the value in JSP you have to do something like:

value="<%=object != null ? object : ""%>" <%-- blech! --%>

Otherwise you get "null". Not that there's anything wrong with a value of 
the string n-u-l-l, I like seeing them sprinkled lightly thoughout my 
pages, giving it that much sougght-after, downtrodden, pessimistic tone.

:P

> Lev Epshteyn wrote:
>> 
>> Hi...
>> 
>> I'm kinda new to Velocity, (coming over from freemarker because i
>> couldn't afford to write wrapper classes for everything from scratch
>> at my new job) and I have a question about all the syntax variants of
>> variable inclusion that velocity has.
>> 
>> What is the purpose of having so many:
>> 
>> $foo
>> $!foo
>> ${foo}
>> $!{foo}
>> 
>> I mean understand how they are different, but for my purposes I do not
>> want to explain the difference to the designer, who I will probably
>> ask to always use $!{foo} because it is the most error-proof one, even
>> though I think it looks awkward. I understand the shorthand reason for
>> allowing $foo to be used, but are the two "saved" characters worth the
>> confusion? Are there situation where you WANT to use $foo instead of
>> $!foo? (I mean why would you want the variable to show up other than
>> for debug purposes?)
> 
> To me, debugging seems like a good enough reason all by itself.
> 
> I found the $! form very useful in the <input> elements, where you
> don't know the value first time around.
> 
> You still have the choice to ask you designers to use only the ${}
> form. Maybe there should be a switch in velocity.properties that
> doesn't allow short syntax...
> 
> Bojan
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org> For additional
> commands, e-mail: <ma...@jakarta.apache.org>


-- 
Nick Bauman 
Cortexity Development
Intellectual Process is more important than
Intellectual Property -- you'll see.
http://www.cortexity.com/


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: So much syntax...

Posted by Bojan Smojver <bo...@binarix.com>.
Lev Epshteyn wrote:
> 
> Hi...
> 
> I'm kinda new to Velocity, (coming over from freemarker because i couldn't
> afford to write wrapper classes for everything from scratch at my new job)
> and I have a question about all the syntax variants of variable inclusion
> that velocity has.
> 
> What is the purpose of having so many:
> 
> $foo
> $!foo
> ${foo}
> $!{foo}
> 
> I mean understand how they are different, but for my purposes I do not want
> to explain the difference to the designer, who I will probably ask to always
> use $!{foo} because it is the most error-proof one, even though I think it
> looks awkward. I understand the shorthand reason for allowing $foo to be
> used, but are the two "saved" characters worth the confusion? Are there
> situation where you WANT to use $foo instead of $!foo? (I mean why would you
> want the variable to show up other than for debug purposes?)

To me, debugging seems like a good enough reason all by itself.

I found the $! form very useful in the <input> elements, where you don't
know the value first time around.

You still have the choice to ask you designers to use only the ${} form.
Maybe there should be a switch in velocity.properties that doesn't allow
short syntax...

Bojan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: So much syntax...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/11/01 11:06 AM, "Lev Epshteyn" <le...@corsis.com> wrote:

> Hi...
> 
> I'm kinda new to Velocity, (coming over from freemarker because i couldn't
> afford to write wrapper classes for everything from scratch at my new job)
> and I have a question about all the syntax variants of variable inclusion
> that velocity has.
> 
> What is the purpose of having so many:
> 
> $foo
> $!foo
> ${foo}
> $!{foo}
> 
> I mean understand how they are different, but for my purposes I do not want
> to explain the difference to the designer, who I will probably ask to always
> use $!{foo} because it is the most error-proof one, even though I think it
> looks awkward. I understand the shorthand reason for allowing $foo to be
> used, but are the two "saved" characters worth the confusion? Are there
> situation where you WANT to use $foo instead of $!foo? (I mean why would you
> want the variable to show up other than for debug purposes?)

Who knows :)  Some people think it's an error to have to use $!foo, because
it means that someone screwed up and the data isn't completely there.

I only use it when I do something like

 <input ...... Value="$!email" />

So that if I do forget, or the db returns null or something, it's no biggie.
Personal choice.

The ${foo} was added to make it clear to the parser what you want in the
case of something like


  You can call the method ${foo}.getText()

(which I am sure you know...)

I find ${foo} to be ugly and require extra typing, so I never use it unless
I have to...  That's again just personal preference...


> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
Be a giant.  Take giant steps.  Do giant things...


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>