Some languages have a .
operator for string concatenation. The oldest language I could find that supports it is Perl. Was Perl the first to use it? Why was it chosen?

- 470
- 2
- 7
-
4Ask Larry. He had some... unique... ideas for why things are the way they are in Perl. – May 28 '15 at 20:48
-
2Wow. So why is this a terrible question, but http://programmers.stackexchange.com/questions/43329/etymology-of-string is ok. Are folks down-voting this because they feel it is off-topic? – eebbesen May 28 '15 at 21:05
-
3@eebbesen because the other question was asked four years ago and is a general term used throughout the industry (and before). On the other hand, this is asked why a particular coder (known for a number of idiosyncrasies) made a particular design choice. – May 28 '15 at 21:11
-
1@MichaelT - This wasn't meant to be Perl-specific. I just couldn't find a reference to the dot being used for string concatenation in any languages older than Perl. I've edited the question to (hopefully) reflect that. – Tyler Holien May 28 '15 at 21:14
1 Answers
If you want to stick with a single non-alphanumeric non-whitespace ASCII character for operators, there really aren't that many. I can only see a couple of alternative choices: !
, ~
, #
, ,
, and $
. Of those, only .
and ,
can be reached without ⇧ on a US keyboard, #
is the comment character. Comma makes kind of sense, but it is already used for a different purpose in C and C-like languages, with which a lot of Perl programmers would also be familiar, and so has the same meaning in Perl.
This leaves you only with the dot. Note that a middle dot (·) is used in maths to denote function composition (and Haskell uses the ASCII dot as an approximation for that), which can be kinda-sorta related to concatenation.
There is, in fact, no standard operator symbol for concatenation in maths, some suggestions are the double plus ⧺
(Haskell uses ++
for concatenation) or the frown ⌢
.
Some languages use +
for concatenation, which is a terrible choice, because concatenation lacks several of the properties that we normally associate with an addition-like operation. Most importantly, concatenation is noncommutative.

- 101,921
- 24
- 218
- 318
-
4`+` is an *ideal* choice for concatenation, *because no one expects joining two strings together to be an arithmetical operation in the first place.* Saying "`+` is bad because it doesn't have the properties of arithmetical addition" is only a valid claim if `+` in this context *not* having the properties of arithmetical addition would violate POLS and confuse users, but since no one expects it to, it is not a bad thing. It's far more *intuitively correct,* producing a string that is the result of adding the contents of one string to another, than `.` is, which intuitively... does what? – Mason Wheeler May 28 '15 at 21:31
-
3@MasonWheeler from the perl world (which this seems to come from), `+` is an arithmetic *only* operator. In the perl world, the operator is only used in one context (string or number) to avoid ambiguities with data types (`"4" + 3` is what? - in perl, it is 7 because `+` is a math operator). Overloading an operator for different contexts is not an option there. – May 28 '15 at 21:39
-
4@MichaelT: The problem with that is weak typing and has nothing to do with operators. `+` for concatenation is a fine choice. Nobody expects literally every symbol in a programming language to have completely and only it's strict mathematical meaning (for most anyway I'm sure there's a few where you have to program in Unicode and strictly mathematical notation). – DeadMG May 28 '15 at 21:44
-
2@DeadMG It is a consequence of weak typing that necessitates a differentiation of operator contexts (or you end up with some other fun). Working from the assumption that perl was the first to use it, the proposed alternative of using `+` isn't an option because of these design decisions. – May 28 '15 at 21:46
-
I'm not contending that it was not a reasonable choice for Perl considering that they already screwed it up and needed to not screw it up any further than it already is. I'm saying that in general, it's not a terrible choice to use + just because it does not obey every mathematical rule that normally surrounds +. – DeadMG May 28 '15 at 21:47
-
I wonder if we think `+` is unsurprising is because of its use in other languages. If there were no `+` and we only had an `add` function, would it be as intuitive? – Tyler Holien May 28 '15 at 21:51
-
I don't think it's unreasonable for newcomers of a language to expect arithmetic operators to behave like they do in arithmetic. If something can be added, I would expect it can also be subtracted, but it's not at all intuitive to me what subtracting two strings would mean. (Of the languages that implement subtraction on strings, do all behave the same way?) – Tyler Holien May 28 '15 at 22:01
-
3@MasonWheeler The problem with + is that it's also overloaded for chars such that the `"a" + 'b'` -> `"ab"` but `'a' + 'b'` -> `195`, which can bite you in the ass when concatenating if you ever end up with two adjacent chars. – Doval May 28 '15 at 22:06
-
1@Doval: Again, this is a *weak typing problem,* not an *operator problem.* It does not exist in languages that don't conflate chars with numbers. – Mason Wheeler May 28 '15 at 22:37