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

Jonathan M Davis jmdavisProg at gmx.com
Thu Jul 5 17:46:11 PDT 2012


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.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list