D's confusing strings (was Re: D on hackernews)
Christophe
travert at phare.normalesup.org
Wed Sep 21 08:16:33 PDT 2011
Timon Gehr , dans le message (digitalmars.D:144889), a écrit :
> unicode natively. Yet the 'D strings are strange and confusing' argument
> comes up quite often on the web.
Well, I think they are. The ptr+length stuff is amasing, but the
behavior of strings in phobos is weird.
mini-quiz: what should std.range.drop(some_string, 1) do ?
hint: what it actually does is not what the documentation of phobos
suggests*...
Strings are array of char, but they appear like a lazy range of dchar to
phobos. I could cope with the fact that this is a little unexpected for
beginners. But well, that creates a lot of exceptions in phobos, like
the fact that you can't even copy a char[] to a char[] with
std.algorithm.copy. And I don't mention all the optimization that are
not/cannot be performed for those strings. I'll just remember to use
ubyte[] wherever I can...
* Please, someone just adds in the documentation of IsSliceable that
narrow strings are an exception, like it was recently added to
hasLength.
--
Christophe
More information about the Digitalmars-d
mailing list