why is string not implicit convertable to const(char*) ?

Wouter Verhelst wouter at grep.be
Thu Jul 5 17:57:05 PDT 2012


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). But
they're far and few between, and it would indeed be silly to switch to
zero-terminated strings.

-- 
The volume of a pizza of thickness a and radius z can be described by
the following formula:

pi zz a


More information about the Digitalmars-d-learn mailing list