Re: String concatenation design
- From: "Rob Thorpe" <robert.thorpe@xxxxxxxxxxxx>
- Date: 28 Mar 2006 05:25:03 -0800
Anton Treuenfels wrote:
So while emotionally attracted to the plus sign I'm not necessarily wedded
to it. Three other possibilities occur to me:
1) use a function, not an operator: STRCAT("s1", "s2").
That's unambiguous and easy to get right semantically. A lot more typing
than "+", though. CAT$() (do my BASIC roots show? *blush*) is shorter but to
me suggests a directory function of some kind.
That's what I would do. Although many languages have many operators
and levels of prescedence in practice programmers don't like them much.
C has ~15 levels of prescedence depending on how you count them, but
programmer generally only use 4 or 5 of them and rely on parenthesis
otherwise.
The advantage of "cat(s1, s2)" over s1 + s2 is that it is obvious that
the operation cat occurs on strings. In order to tell what s1 + s2
does the user must remember their type.
3) pick a currently unused symbol (or one that only appears in some
non-conflicting context) to use as the concatenation operator. But what
might be a good, easily remembered choice? "&", maybe?
As far as I can tell these differ mostly at the visible, source level. Once
converted into RPN form they all boil down to two operands and one operator.
Yep.
So is any one of these clearly better than the others as far as the user is
concerned?
I don't think so.
Something you may notice though is that the more symbols you use for
operations the fewer the user has available for variable names. In
lisp for example "&" has no meaning, so it can be used in variable
names, which is quite useful.
.
- Follow-Ups:
- Re: String concatenation design
- From: Oliver Wong
- Re: String concatenation design
- References:
- String concatenation design
- From: Anton Treuenfels
- String concatenation design
- Prev by Date: Re: how to print all the combinations ??
- Next by Date: Re: String concatenation design
- Previous by thread: Re: String concatenation design
- Next by thread: Re: String concatenation design
- Index(es):