D's confusing strings (was Re: D on hackernews)

Christophe travert at phare.normalesup.org
Wed Sep 21 14:08:10 PDT 2011


Jonathan M Davis , dans le message (digitalmars.D:144944), a écrit :
>> I never said there was a problem with drop.
> 
> Yes you did. You said:
> 
> "mini-quiz: what should std.range.drop(some_string, 1) do ?
> hint: what it actually does is not what the documentation of phobos 
                                              ^^^^^^^^^^^^^^^^^^^^^^^
> suggests*..."
not documentation of drop.

> If you have a better solution, please share it, but the fact that we want both 
> efficiency and correctness binds us pretty thoroughly here.

- char[], etc. being real arrays.
- strings being lazy ranges of dchar, providing access to underlying 
char[].

Correctness of the langage is better, since we don't have a T[] having a 
front method that returns something else than T, or a type that accepts 
opSlice but is not sliceable, etc.

Runtime correctness and efficiency are the same as the current ones, 
since the whole phobos already considers strings as lazy range of dchar. 
It is even better, since the user cannot change an arbitrary code point 
in a string without explicitely asking for the undelying char[]. 
Optimizations can come the same way as they currently can, since the 
underlying char is accessible.

I can deal with strings the way they are, since they are an heritage. 
They are not perfect, and will never be unless computers become fat 
enough to treat dchar[] just as efficiently as char[]. I am also aware 
that phobos cannot be optimized for every cases in the first place, and 
I can change my mind.

-- 
Christophe


More information about the Digitalmars-d mailing list