You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Daniel Dekany <dd...@freemail.hu> on 2002/05/01 18:45:15 UTC

Re: String concatenation Was: Give it a whirl...

Tuesday, April 30, 2002, 12:42:21 PM, Jeff Schnitzer wrote:

>> From: Denis [mailto:jido@respublica.fr]
>> 
>> Several people have expressed concerns about operator overloading,
>> including Geir.
>> I think we should put aesthetic <*phew! spelling*> considerations
> aside
>> and choose a different operator than +.
>> 
>> The largest agreement seems to be on ":", so we can go with this one.
[snip]
> I think all this concern about overloading is silly.  At some point you
> must stop assuming that designers are idiots; after all, these are often
> the same people writing JavaScript that makes my head spin.  Yeah, some
> rare cases might be misleading.  Ok, so it's not perfect.  The benefit
> of '+' is that nobody has to go looking through the manual to figure out
> what the concatenation operator is.  If you compare the total time which
> would be consumed by the occasional 1-hour bewilderment at "1" + 1 cases
> and compare it to the total time which would be consumed by the millions
> of 3-minute manual searches, I think net conservation of man-hours
> favors '+'.

You must read the documentation if you want to know how to concatenate
strings. It does not mater if the cat. op. is + or : or even -@///@-,
you still have to find it in the documentation. Or will you give a tip
that it is +, and try it? Perhaps this is just me but I always read
the documentation and don't try to guess. So the "3-minute manual
searches" are there for + too.

Then. Which one is easier to learn (to understand):

a) + is the artematical addition op. and the op. of str cat in one.
It is chosen in runtime which meaning holds. If all arguments of the
op. are String-s, then it is str cat. If you try to add String-s to
non-Strings then it is a runtime error.

b) : is the str cat operator. 'Foo' : $x : 'Baaz' : 'Wombat' is
basically the same as "Foo${x}BaazWombat" but with : you can break
your string into multiple lines in you template.

> ...and if it really, really has to be something other than '+', use '&'
> or something else which has normal human semantic meaning.  Please
> *don't* go hunting through the keyboard to find a character that hasn't
> been used yet.  That's what gave us Perl.

It is perhaps just me again... but when I learn a new language I spend
90% of my time with understanding the "mental model"/semantic and 10%
with memorizing the syntax. So I really don't care if str cat is : or
++ or @ or #. I can accept & too but I bet that many people will mix
it up with &&.

What makes Perl a nightmare for me is not it's undoubtedly "keyboard
hunting" syntax but it's really complex and strange semantic. I tend
to say that while programmer who *really* understands C++ is
exceptionally rare, programmer who *really* understands Perl is Larry
Wall.


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


Re: String concatenation Was: Give it a whirl...

Posted by Nathan Bubna <na...@esha.com>.
Geir said:
[snip]
> I like "+" because of familairity, but prefer not to overload.  I
therefore
> like "&" because of its use in other lighter programming environments
(like
> VB) so there may be some familiarity with people.

i'm remembering some proverb about familiarity and contempt... how'd that go
again? :-)

> I didn't mind "." either.

-1!  please don't go with that, i'd prefer '-@///@-'!  ...ok, not really,
but almost! :-)

> I don't like ":" because it's so similar to what you use for namespace
> declination (or whatever the right word is) in XML.

hmm, i didn't think of that (don't do much of it myself), but i expect that
we could find some similar operator for pretty much any reasonable
suggestion here.  just imagine if someone were generating perl code with
velocity... no, wait, don't do that.  i don't want to give anyone
nightmares. :-)

> It seems that while the below XML generation example is lucidly clear, I
> would imagine it could be confusing to some :
>
> #if($whatever == true)
>
>    <$namespace:$foobar attrib="get:$arg" />
>
> #else

no problems, but yeah, it could be confusing.  still, i'd rather have visual
confusion with a non-vtl syntax (as above), than with vtl like &&.   i can
live with &, but for largely subjective reasons, i just think : is nicer.

Nathan Bubna
nathan@esha.com


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


Re: String concatenation Was: Give it a whirl...

Posted by "McLaughlin, Jim" <ji...@stonewatersoftware.com>.
> On 5/1/02 10:47 PM, "McLaughlin, Jim" <ji...@stonewatersoftware.com>
> wrote:
>
>> Might as well get my 2 bits in:
>>
>> "::" has precedence as the cons operator in ML, unless that brings
>> back bad memories for people.  Geir will probably dislike it twice as
>> much :).
>>  I
>> agree that overloading is a bit nasty since we aren't strongly typed
>> (not even a type system, really).  I'm afraid if we go with the vb '&'
>> a velocity.net won't be far behind, so I'll throw in with ':'.
>
>
> I would welcome velocity.NET with open arms :)
>
> I keep thinking about porting Velocity to C# for fun.

Nice troll.  I can't wait to see my fn mailbox tomorrow!

-- 
Jim McLaughlin
Software Engineer
Stonewater Software
email: jim@stonewatersoftware.com
Phone: 847.864.1060 x107
Fax  : 847.864.1238



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


Re: String concatenation Was: Give it a whirl...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 5/1/02 10:47 PM, "McLaughlin, Jim" <ji...@stonewatersoftware.com> wrote:

> Might as well get my 2 bits in:
> 
> "::" has precedence as the cons operator in ML, unless that brings back bad
> memories for people.  Geir will probably dislike it twice as much :).
>  I
> agree that overloading is a bit nasty since we aren't strongly typed (not
> even a type system, really).  I'm afraid if we go with the vb '&' a
> velocity.net won't be far behind, so I'll throw in with ':'.


I would welcome velocity.NET with open arms :)

I keep thinking about porting Velocity to C# for fun.


> 
>>  Geir> I like "+" because of familairity, but prefer not to overload.
>> 
>> Me too.  So how about "++"?
>> 
>> Like Nathan, I dislike '&'.  But I dislike "." and ":" more.
>> 
> 
> 

-- 
Geir Magnusson Jr.                       geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.



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


Re: String concatenation Was: Give it a whirl...

Posted by "McLaughlin, Jim" <ji...@stonewatersoftware.com>.
Might as well get my 2 bits in:

"::" has precedence as the cons operator in ML, unless that brings back bad
memories for people.  Geir will probably dislike it twice as much :).  I
agree that overloading is a bit nasty since we aren't strongly typed (not
even a type system, really).  I'm afraid if we go with the vb '&' a
velocity.net won't be far behind, so I'll throw in with ':'.

>  Geir> I like "+" because of familairity, but prefer not to overload.
>
> Me too.  So how about "++"?
>
> Like Nathan, I dislike '&'.  But I dislike "." and ":" more.
>



-- 
Jim McLaughlin
Software Engineer
Stonewater Software
email: jim@stonewatersoftware.com
Phone: 847.864.1060 x107
Fax  : 847.864.1238



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


Re: String concatenation Was: Give it a whirl...

Posted by Tim Pizey <ti...@paneris.org>.
Hi, 
Thanks and admiration from a lurker.

+,.    - I would assume might well be string concatenators
&,:    -I would be doubtful and would seek the documentation.

Whilst I applaud those who read all the docs before tampering 
with code lots of others surf a command set or muddle through.

Isn't it fair to assume that those having to deal with this syntax 
will have been exposed to the syntax of an ordered set of 
languages:
1. javascript
2. java
3. perl 
There won't be that many who have perl but no java, this is 
a Jakarta project after all.
Nobody thanks you for introducing unprecedented variance.

Thanks for taking such pains about these decisions, 
it is this that gives Velocity its quality.
cheers
timp


 

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


Re: String concatenation Was: Give it a whirl...

Posted by Denis <ji...@respublica.fr>.
On Thursday, May 2, 2002, at 12:21 AM, Daniel Dekany wrote:

> To make designers happier:
> #set($foo = "bar" :-) $tutu :-) "wombat")

+1!
and +1!

:-)
-- Denis.


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


Re: String concatenation Was: Give it a whirl...

Posted by Daniel Dekany <dd...@freemail.hu>.
Wednesday, May 1, 2002, 10:28:25 PM, Mike Williams wrote:

>   Geir> I like "+" because of familairity, but prefer not to overload.  
>
> Me too.  So how about "++"?

Belive or not '++' was one of may serious ideas but I didn't dared to
tell it since I know that many people become wild when (s)he sees
patterns like this. Unfortunately it resembles to
C/C++/Java/Perl/JavaScript inc. op. but all usable character sequence
is used somewhere... But it is easy to type.

#set($foo = "bar" ++ $tutu ++ "wombat")

But I still prefer ':'.

> Like Nathan, I dislike '&'.  But I dislike "." and ":" more.

So the task is simple. Here are all other chars in US-ASCII repertoire
which could be used as str cat.:

% ; ? @ \ ^ ` { | } ~

chose one! :)
Or we can chose a character sequence:

To make designers happier:
#set($foo = "bar" :-) $tutu :-) "wombat")

To make the code more understandable for new users:
#set($foo = "bar" {string concatenation} $tutu {string concatenation} "wombat")

To make Geir happier ;) :
#set($foo = $cat(["bar", $tutu, "wombat"]))

Amm... sorry. :)

So I think we are out of usable characters and character sequences.
Either we chose one of these as str cat operator: ':' '&' '++' or we
do runtime operator overloading of '+'. I just say that it is perhaps
not a good idea to complicate something with things like runtime
operator overlading just because human feels '+' more cat-ish than ':'
because of psychic reasons. Geir, can the community decide somehow
(poll or something...)?

Some test cases:


*** Test 1. ***

#set($tutu = 1)

Without str cat:
  #set($foo = "bar${tutu}wombat")

With ':'
  #set($foo = "bar" : $tutu : "wombat")
or even
  #set($foo = "bar" : "$tutu" : "wombat")

With '+'
  #set($foo = "bar" + "$tutu" + "wombat")
But this is a runtime error if $tutu is not a String:
  #set($foo = "bar" + $tutu + "wombat")


*** Test 2. ***

With ':' it is str cat for sure:
  #set($pizsama = $traktor : $szekerce)

With overloaded '+' is is either str cat or aretmatheticicaldalsdlasl
addition or an error depending on the current values of $traktor and
$szekerce:
  #set($pizsama = $traktor + $szekerce)
However we can be finesse and force str cat:
  #set($pizsama = "$traktor" + "$szekerce")


*** Test 3. ***

#set($a = 10)
#set($b = 5)

With ':'
  #set($foo = "I have " : $a + $b : " dollar(s).")

With overloaded '+'
  #set($tmp = $a + $b)
  #set($foo = "I have " + "$tmp" + " dollar(s).")

  
*** Test 4. ***

#set($lue = "10")

With ':' it is "210":
  #set($foo = 2 : $lue)

With overloaded '+' it is an error:
  #set($foo = 2 + $lue)
However it is "210":
  #set($foo = "2" + $lue)


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


Re: String concatenation Was: Give it a whirl...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 5/1/02 4:28 PM, "Mike Williams" <md...@bigfoot.com> wrote:

> Geir> I like "+" because of familairity, but prefer not to overload.
> 
> Me too.  So how about "++"?

No :)

> 
> Like Nathan, I dislike '&'.  But I dislike "." and ":" more.

I recently did a little scripty lang where I added a "streq" operator to
make it very clear that the operands would be treated as strings - the
operators in the lang coerced type, so == forced things to int ->  so "1" ->
1. (It made sense in the problem domain... Data was coming un untyped...)

Hoever, I can't think of any tokens for add that wouldn't make me gag.

Seems like '&' is disliked the least :)


-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting

The cost of synchronization is much less that the cost of stupidity.


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


Re: String concatenation Was: Give it a whirl...

Posted by Mike Williams <md...@bigfoot.com>.
  Geir> I like "+" because of familairity, but prefer not to overload.  

Me too.  So how about "++"?

Like Nathan, I dislike '&'.  But I dislike "." and ":" more.

-- 
cheers,
Mike

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


Re: String concatenation Was: Give it a whirl...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 5/1/02 1:19 PM, "Geir Magnusson Jr." <ge...@optonline.net> wrote:

> On 5/1/02 1:11 PM, "Nathan Bubna" <na...@esha.com> wrote:
> 
>> Geir said:
>>> Why don't you like &?
>> 
>> eh, various reasons have already been thrown out, but personally, it's the
>> similarity to && in velocity, similarity to bit-wise & in java, general
>> aesthetics (i think : looks nicer), and : is easier/quicker to type.   (not
>> necessarily in that order :-)
>> 
> 
> That's fair.  Just wondering.
> 
> I like "+" because of familairity, but prefer not to overload.  I therefore
> like "&" because of its use in other lighter programming environments (like
> VB) so there may be some familiarity with people.
> 
> I didn't mind "." either.
> 
> I don't like ":" because it's so similar to what you use for namespace
> declination (or whatever the right word is) in XML.
> 
> 
> It seems that while the below XML generation example is lucidly clear, I
> would imagine it could be confusing to some :
> 
> #if($whatever == true)
> 
>  <$namespace:$foobar attrib="get:$arg" />

Actually, the above "get:$arg" isn't problematic, but you could see how it
might be confusing.

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


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


Re: String concatenation Was: Give it a whirl...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 5/1/02 1:11 PM, "Nathan Bubna" <na...@esha.com> wrote:

> Geir said:
>> Why don't you like &?
> 
> eh, various reasons have already been thrown out, but personally, it's the
> similarity to && in velocity, similarity to bit-wise & in java, general
> aesthetics (i think : looks nicer), and : is easier/quicker to type.   (not
> necessarily in that order :-)
> 

That's fair.  Just wondering.

I like "+" because of familairity, but prefer not to overload.  I therefore
like "&" because of its use in other lighter programming environments (like
VB) so there may be some familiarity with people.

I didn't mind "." either.

I don't like ":" because it's so similar to what you use for namespace
declination (or whatever the right word is) in XML.


It seems that while the below XML generation example is lucidly clear, I
would imagine it could be confusing to some :

#if($whatever == true)

   <$namespace:$foobar attrib="get:$arg" />

#else

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
The obvious solutions are challenging


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


Re: String concatenation Was: Give it a whirl...

Posted by Nathan Bubna <na...@esha.com>.
Geir said:
> Why don't you like &?

eh, various reasons have already been thrown out, but personally, it's the
similarity to && in velocity, similarity to bit-wise & in java, general
aesthetics (i think : looks nicer), and : is easier/quicker to type.   (not
necessarily in that order :-)

Nathan Bubna
nathan@esha.com


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


Re: String concatenation Was: Give it a whirl...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 5/1/02 1:01 PM, "Nathan Bubna" <na...@esha.com> wrote:

> Daniel said:
>> You must read the documentation if you want to know how to concatenate
>> strings. It does not mater if the cat. op. is + or : or even -@///@-,
>> you still have to find it in the documentation.  [snip]
> 
> hmm.  maybe we should go with -@///@-  as the str cat operator... after all,
> notoriety can sometimes be good publicity, right?
> 
> :-)  i'm kidding, of course.
> 
> For what it's worth, here's my opinion:
> 
> -1 on overloading '+'
> 
> -1 on using '&' instead
> 
> +1 on using ':' such that:
> 
> #set( $bar = 2 )
> #set( $woogie = $tool.returnArbitraryObject() )
> #set( $foo = "whatever$bar$woogie" )
> 
> is equivalent to
> 
> #set( $bar = 2 )
> #set( $woogie = $tool.returnArbitraryObject() )
> #set( $foo = 'whatever' : $bar : $woogie )
> 
> what can i say?  i like that best.  i'll leave out arguments as i think
> pretty much everything's been said.
> 

Why don't you like &?

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


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


Re: String concatenation Was: Give it a whirl...

Posted by Nathan Bubna <na...@esha.com>.
Daniel said:
> You must read the documentation if you want to know how to concatenate
> strings. It does not mater if the cat. op. is + or : or even -@///@-,
> you still have to find it in the documentation.  [snip]

hmm.  maybe we should go with -@///@-  as the str cat operator... after all,
notoriety can sometimes be good publicity, right?

:-)  i'm kidding, of course.

For what it's worth, here's my opinion:

-1 on overloading '+'

-1 on using '&' instead

+1 on using ':' such that:

#set( $bar = 2 )
#set( $woogie = $tool.returnArbitraryObject() )
#set( $foo = "whatever$bar$woogie" )

is equivalent to

#set( $bar = 2 )
#set( $woogie = $tool.returnArbitraryObject() )
#set( $foo = 'whatever' : $bar : $woogie )

what can i say?  i like that best.  i'll leave out arguments as i think
pretty much everything's been said.

Nathan Bubna
nathan@esha.com


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