why is string not implicit convertable to const(char*) ?
Timon Gehr
timon.gehr at gmx.ch
Thu Jul 5 18:27:02 PDT 2012
On 07/06/2012 02:57 AM, Wouter Verhelst wrote:
> Jonathan M Davis<jmdavisProg at gmx.com> writes:
>
>> On Thursday, July 05, 2012 21:32:11 dcoder wrote:
>>> Thanks for the thorough explanation, but it begs the question why
>>> not make strings be array of chars that have \0 at the end of it?
>>> Since, lots of D programmers were/are probably C/C++
>>> programmers, why should D be different here? Wouldn't it
>>> facilitate more C/C++ programmers to come to D?
>>>
>>> Just curious.
>>
>> Are you serious? I'm shocked to hear anyone suggest that. Zero-terminated
>> strings are one of the largest mistakes in programming history. They're
>> insanely inefficient. In fact, IIRC Walter Bright has stated that he thinks that
>> having arrays without a length property was C's greatest mistake (and if
>> they'd had that, they wouldn't have created zero-terminated strings).
>>
>> C++ tried to fix it with std::string, but C compatability bites you everywhere
>> with that, so it only halfway works. C++ programmers in general would probably
>> have thought that the designers of D were idiots if they had gone with zero-
>> terminated strings.
>>
>> You don't do what another language did just to match. You do it because what
>> they did works and you have no reason to change it. Zero-terminated strings
>> were a horrible idea, and we're not about to copy it.
>
> To be fair, there are a _few_ areas in which zero-terminated strings may
> possibly outperform zero-terminated strings (appending data in the case
> where you know the memory block is large enough, for instance).
It is impossible to know that the memory block is large enough unless
the length of the string is known. But it isn't.
> But they're far and few between, and it would indeed be silly to switch to
> zero-terminated strings.
>
There is no string manipulation that is significantly faster with
zero-terminated strings.
More information about the Digitalmars-d-learn
mailing list