What is the etymology of the “dot” operator for string concatenation?
https://softwareengineering.stackexchange.com/questions/285229
質問
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?
解決
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.