First Impressions
Anders F Björklund
afb at algonet.se
Tue Oct 3 03:20:03 PDT 2006
Kevin Bealer wrote:
> If we say 'char[]' then users don't know it's a string until they read
> the 'why D arrays are great' page (which they should read, but...)
>
> If we say 'string' then we hide the fact that [] can be applied and that
> other array-like operations can work.
Which could be a *good* thing, since it would stop users from hurting
themselves by pretending that the D strings are arrays of characters ?
And when they have read up that they are "arrays of Unicode code units",
they should be OK with interpreting the "string" alias as char[] arrays.
> For instance, from a Java perspective:
>
> char[] : Users don't know that it's "String"; users see it as low-level.
> Some will try to write things like 'find()' by hand since they
> will figure arrays are low level and not expect this to exist.
>
> string : Users will think it's immutable, special; they will ask "how do
> I get one of the characters out of a string", "how do I convert
> string to char[]?", and other things that would be obvious
> without the alias.
I think the best answer would be: "to get a char[] from the string,
use the std.utf.toUTF8 function", since this also works even if you
redeclare the "string" alias to be something else - like wchar_t[] ?
Earlier* I suggested adding the alias utf8_t for "char", just like
we have int8_t for "byte", but I wouldn't rename the actual D types.
Just a little std.stdutf module with some aliases, if ever needed...
string std.string.toString( )
utf8_t[] std.utf.toUTF8( )
utf16_t[] std.utf.toUTF16( )
utf32_t[] std.utf.toUTF32( )
--anders
* digitalmars.D/11821, 2004-10-15
More information about the Digitalmars-d
mailing list