std.algorithm.remove and principle of least astonishment

Steven Schveighoffer schveiguy at yahoo.com
Mon Nov 22 07:37:48 PST 2010


On Sun, 21 Nov 2010 23:56:17 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> If you want to work with arrays, use a[0] to access the front, a[$ - 1]  
> to access the back, and a = a[1 .. $] to chop off the first element of  
> the array. It is not AT ALL natural to mix those with a.front, a.back  
> etc. It is not - why? because std.range defines them with specific  
> meanings for arrays in general and for arrays of characters in  
> particular. If you submit to use std.range's abstraction, you submit to  
> using it the way it is defined.

I want to use char[] as an array.  I want to sort the array, how do I do  
this?  (assume array.sort as a property is deprecated, as it should be)

The problem is that the library *won't let you* treat them as arrays.   
Some functions see char[] as an array, and some see them as a range of  
dchars, you can't declare to those functions "No! this is an array!" or  
"No, this is a dchar range!"  That is the main problem I see with how the  
current code works.

BTW, you may not understand that we don't want to go back to the days of  
'byDchar'.  We want strings (including literals) to be special type  
because they are a special type (not an array).

-Steve


More information about the Digitalmars-d mailing list