www.digitalmars.com         C & C++   DMDScript  

D - why ~? Why not +?

reply Nathanael Nerode <Nathanael_member pathlink.com> writes:
So, why does D overload ~ and ~= for string concatentation?
The obvious choices are + and +=.  If there's a complaint about a conflict with
pointer arithmetic, well, pointer arithmetic is horrifying anyway, and should be
used a lot less often in normal programming than string concatentation.  Since D
understands arrays, you don't need to use pointer arithmetic to work around the
C messiness of treating all strings as char pointers.  Since D has strong
typing, it should know the difference between a char array (concat-able) and a
char pointer anyway.
May 01 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Nathanael Nerode" <Nathanael_member pathlink.com> wrote in message
news:aap078$vlg$1 digitaldaemon.com...

 So, why does D overload ~ and ~= for string concatentation?
 The obvious choices are + and +=.  If there's a complaint about a conflict
with
 pointer arithmetic, well, pointer arithmetic is horrifying anyway, and
should be
 used a lot less often in normal programming than string concatentation.
Since D
 understands arrays, you don't need to use pointer arithmetic to work
around the
 C messiness of treating all strings as char pointers.  Since D has strong
 typing, it should know the difference between a char array (concat-able)
and a
 char pointer anyway.
However, just like in C, name of array is a pointer to its contents. So, if foo is a char[], both would be legal: foo + "666" foo + 666 With ~, there is no such ambiguity. It is clear, where the concatenation happens, and where it is the addition or a shift.
May 01 2002