std.algorithm.remove and principle of least astonishment

Jonathan M Davis jmdavisProg at gmx.com
Sun Nov 21 16:48:53 PST 2010


On Sunday 21 November 2010 16:12:14 Rainer Deyke wrote:
> >>> It may be wise in fact to start using D2 and make criticism grounded in
> >>> reality that could help us improve the state of affairs.
> >> 
> >> Sorry, but no.  It would take a huge investment of time and effort on my
> >> part to switch from C++ to D.  I'm not going to make that leap without
> >> looking first, and I'm not going to make it when I can see that I'm
> >> about to jump into a spike pit.
> > 
> > You may rest assured that if anything, strings are not a problem.
> 
> I'm not concerned about strings, I'm concerned about *arrays*.  Arrays
> of T, where T may or not be a character type.  I see that you ignored my
> Vector!char example yet again.
> 
> Your assurances aren't increasing my confidence in D, they're decreasing
> my confidence in your judgment (and by extension my confidence in D).

Character arrays are arrays of code units and ranges of code points (of dchar 
specifically). If you want them to be treated as code points, access them as 
ranges. If you want to treat them as code units, access them as arrays. So, as 
far as character arrays go, there shouldn't be any problems. You just have to be 
aware of the difference between a char or wchar and a character.

Now, as for Array!char or any other container which could be considered a 
sequence of code units, there, we could be in trouble if we want to treat them 
as code points rather than code units. I believe that ranges over them would be 
over code units rather than code points, and if that's the case, you're going to 
have to deal with char and wchar as arrays if you want to treat them as ranges 
of dchar. We should be able to get around the problem by special-casing the 
containers on char and wchar, but that would mean more work for anyone 
implementing a container where it would be reasonable to see its elements as a 
sequence of code units making up a string. It's quite doable though.

- Jonathan M Davis


More information about the Digitalmars-d mailing list