Why I (Still) Won't Use D
Walter Bright
newshound1 at digitalmars.com
Thu Mar 27 14:51:37 PDT 2008
Benji Smith wrote:
> STRINGS
>
> The existence of three different string types (six, if you count
> const/mutable variations of each) makes text-processing more difficult
> than it ought to be.
I have a hard time agreeing with that. While the multiple types give one
options, you can just use one type (string) and ignore all the others.
I've done string processing in D, and it's a LOT less work than in C++.
Furthermore, the internationalization works, unlike C++.
C++ won't save anyone from multiple string types. First of all, char
types in C++ are implementation defined. The code doesn't work from one
compiler to another. Next, C++0x is adding (you guessed it!) wchar and
dchar types. C++0x will have char, signed char, unsigned char, wchar_t,
char16_t, and char32_t as native types, plus volatile/const modifiers,
making for 18 character types! Next, we have char[], vector<char>, and
string<char>, making for 54 string types, more than half of which are
implementation defined.
> I would have liked to see just one string type, with encoding kept as an
> internal implementation detail.
That would be nice, but it is not practical for a systems programming
language. The tradeoffs between char[], wchar[] and dchar[] are quite
real and should be in the choice domain of the programmer.
> And I'd much rather have a string class
> than to treat strings as character arrays
I can't think of any advantage for that.
> (especially since
> indexing/slicing deals with code-points rather than character positions).
This is more of a theoretical problem than an actual one in my
experience. For the cases where it is necessary,
foreach (dchar c; s)
...
will automatically decode UTF-8 strings quite nicely.
Note that neither C++ nor Java handles this at all. Java tried to do it
with 16 bit chars, but that got torpedoed when the Unicode standard
adopted surrogate pairs.
I consider the string support in D to be one of its great strengths.
I've written text processing programs in D, including fully
internationalized ones, and it's a breeze compared with doing it in C++
or Java. It runs faster, too!
More information about the Digitalmars-d
mailing list