std.algorithm.remove and principle of least astonishment

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Oct 16 14:34:42 PDT 2010


On 10/16/2010 03:14 PM, Steven Schveighoffer wrote:
> On Sat, 16 Oct 2010 15:51:23 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> On 10/16/2010 01:39 PM, Steven Schveighoffer wrote:
>>> I suggest wrapping a char[] or wchar[] (of all constancies) with a
>>> special range that imposes the restrictions.
>>
>> I did so. It was called byDchar and it would accept a string type. It
>> sucked.
>>
>> char[] and wchar[] are special. They embed their UTF affiliation in
>> their type. I don't think we should make a wash of all that by
>> handling them as arrays. They are not arrays.
>
> The compiler thinks they are. And they look like arrays (T[] looks like
> an array to me no matter what T is). And I *want* an array of characters
> in most cases. If you want a special type for strings, make them a
> special type.
>
> D should not have this schizophrenic view of strings. Plus it strikes me
> as extremely unclean and bloated for every algorithm that might have a
> range of char's passed into it to treat it specially (ignoring what the
> compiler says).

It would do wrong or useless things otherwise. I'd probably do some 
things differently if I started over, but given the circumstances I 
think std.algorithm does the best it could ever do with strings.

Andrei



More information about the Digitalmars-d mailing list