Arithmetical operations should be limited to types that act like arithmetical values. It is bad enough that the sum of two strings is a third string. Conflating the addition operation with string concatenation is a questionable choice because string concatenation obeys very few of the rules of addition; in particular, a + b != b + a
.
But to go there for string builders -- which are by definition mutable state and not arithmetical values -- is horrid. The sum of two things should be a third thing that differs from the two summands. That is, a += b
must have the same semantics as a = a + b
and not a.MutateWith(b)
. If there isn't an assignment to a
at the end then compound assignment is the wrong operator.
More generally: never make cutesy operator overloads. Operator overloads are there so that you can make two complex numbers add to a third, not so that you can make an customer plus a jar of peanut butter equal a purchase order, or some such silliness.