string is rarely useful as a function argument

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Dec 28 10:56:22 PST 2011


On 12/28/11 12:46 PM, Walter Bright wrote:
> On 12/28/2011 10:35 AM, Peter Alexander wrote:
>> On 28/12/11 6:15 PM, Walter Bright wrote:
>>> If such a change is made, then people will use const string when they
>>> mean immutable, and the values underneath are not guaranteed to be
>>> consistent.
>>
>> Then people should learn what const and immutable mean!
>>
>> I don't think it's fair to dismiss my suggestion on the grounds that
>> people
>> don't understand the language.
>
> People do what is convenient, and as endless experience shows, doing the
> right thing should be easier than doing the wrong thing. If you present
> people with a choice:
>
> #1: string s;
> #2: immutable(char)[] s;
>
> sure as the sun rises, they will type the former, and it will be subtly
> incorrect if string is const(char)[].
>
> Telling people they should know better and pick #2 instead is a strategy
> that never works very well - not for programming, nor any other endeavor.

Yes. Contrary to the OP, I don't think it's fair to dismiss a valid 
concern by framing it as a user education issue. It's has very often 
been aired in the olden days of C++, and never in a winning argument. 
(Right off the bat - auto_ptr.)

Andrei


More information about the Digitalmars-d mailing list