First Impressions
Geoff Carlton
gcarlton at iinet.net.au
Fri Sep 29 18:15:45 PDT 2006
Walter Bright wrote:
> Derek Parnell wrote:
>> And is it there yet? I mean, given that a string is just a lump of
>> text, is
>> there any text processing operation that cannot be simply done to a
>> char[]
>> item? I can't think of any but maybe somebody else can.
>
> I believe it's there. I don't think std::string or java.lang.String have
> anything over it.
>
>> And if a char[] is just as capable as a std::string, then why not have an
>> official alias in Phobos? Will 'alias char[] string' cause anyone any
>> problems?
>
> I don't think it'll cause problems, it just seems pointless.
Hi,
The main reasons I think are these:
It simplifies the initial examples, particularly main(string[]), and
maps such as string[string]. More complex examples are a map of words
to text lines, string[][string], rather than char[][][char[]].
It clarifies the actual use of the entity. It is a text string, not
just a jumbled array of characters. Arrays of char can be used for
other things, such as the set of player letters in a scrabble game. A
string has the additional usage that we know it as is text string. The
alias reflects that intent.
Given a user wants to use a string, there is no need to expose the
implementation detail of how strings are done in D. Perhaps in perl,
strings are a linked list of shorts, but it doesn't mean that you'd have
list<short> all over the place.
Use of char[] and char[][] looks like low level C. It has also been
noted that it encourages char based indexing, which is not a good thing
for utf8.
Anyway, hope one of those points grabbed you!
Geoff
More information about the Digitalmars-d
mailing list