From the manual:
While
*
may seem like a surprising choice to users of languages that provide+
for string concatenation, this use of*
has precedent in mathematics, particularly in abstract algebra.In mathematics,
+
usually denotes a commutative operation, where the order of the operands does not matter. An example of this is matrix addition, whereA + B == B + A
for any matricesA
andB
that have the same shape. In contrast,*
typically denotes a noncommutative operation, where the order of the operands does matter. An example of this is matrix multiplication, where in generalA * B != B * A
. As with matrix multiplication, string concatenation is noncommutative:greet * whom != whom * greet
. As such,*
is a more natural choice for an infix string concatenation operator, consistent with common mathematical use.
Sometimes I define my own operator methods. Should I use +
only for commutative operations?