May 01, 2002 why ~? Why not +? | ||||
---|---|---|---|---|
| ||||
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 Re: why ~? Why not +? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nathanael Nerode | "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. |
Copyright © 1999-2021 by the D Language Foundation