On 06/27/2012 08:09 PM, Steven Schveighoffer wrote:
On Wed, 27 Jun 2012 13:30:48 -0400, Jonathan M Davis
<[email protected]> wrote:
I don't see why having the literal be a string would make anything
confusing.
The fact that a string is considered a range of dchar rather than char
could
be, but I don't see why having a string literal be a dstring instead of a
string would help with that. Besides, it's generally expected that
you'll use
string for strings unless you specifically need wstring or dstring for
some
reason.
No, the reason is:
1. T[] is a range of T, unless T == char or T == wchar, and then it's a
range of dchar (huh?)
2. char[] is not a random access range, even though str[i] and
str.length work.
The fundamental flaw in the way this works is that phobos is pretending
immutable(char)[] is not an array. immutable(char)[] should be an array
of immutable char, string should be a *separate type* of a range of
dchar, perhaps with immutable(char)[] as its underlying storage.
D needs a full, library-defined string type. Until it has that, it's
going to cause endless confusion and WATs.
-Steve
There is no reason for anyone to be confused about this endlessly. It
is simple to understand. Furthermore, think about the implications of a
library-defined string type: it just introduces the problem of what the
type of built-in string literals should be. This would cause endless
pain with type deduction, ifti, string mixins, ... A library-defined
string type cannot be a full string type. Pretending that it can has no
value.
alias immutable(char)[] string is just fine.