D - why ~ for string concat? why not +?
- neroden twcny.rr.com (5/5) May 01 2002 Just discovered D. My first question is, why overload ~ and ~= for stri...
- Walter (17/22) May 01 2002 course
Just discovered D. My first question is, why overload ~ and ~= for string concatenation? These are very odd choices. The natural choices are of course + and +=. If you don't want to do that because of a conflict with pointer arithmetic, consider that pointer arithmetic without intermediate conversion to integer types is a horrifying misfeature. :-)
May 01 2002
<neroden twcny.rr.com> wrote in message news:aaova1$srd$1 digitaldaemon.com...Just discovered D. My first question is, why overload ~ and ~= for string concatenation? These are very odd choices. The natural choices are ofcourse+ and +=. If you don't want to do that because of a conflict with pointer arithmetic, consider that pointer arithmetic without intermediateconversion tointeger types is a horrifying misfeature. :-)The reason was to save + and += on arrays to do an element-by-element add, such as a matrix add. Overloading + to mean "add" in once context and "concatenate" in another leads to ambiguity bugs like: "123" + 4 Does this produce the string: "1234" or the number: 127 ? There is no such ambiguity in D's approach, and so no need to invent an arbitrary, obscure, and forgettable rule about what to do in ambiguous cases.
May 01 2002








"Walter" <walter digitalmars.com>