First Impressions

Walter Bright newshound at digitalmars.com
Sat Sep 30 21:18:02 PDT 2006


Derek Parnell wrote:
>>  (2) may, but char[] has no use 
>> other than that of being a string, as a char[] is always a string and a 
>> string is always a char[]. So I don't think string fits (2).
>  
> This is a lttle more debatable, but not worth generating hostility.

I certainly hope this thread doesn't degenerate into that like some of 
the others.

> A string of text contains characters whose position in the string is
> significant - there are semantics to be applied to the entire text. It is
> quite possible to conceive of an application in which the characters in the
> char[] array have no importance attached to their relative position within
> the array *where compared to neighboring characters*. The order of
> characters in text is significant but not necessarily so in a arbitary
> character array. 
> 
> Conceptually a string is different from a char[], even though they are
> implemented using the same technology.

You do have a point there.

>> And lastly, there's the inevitable confusion. People learning the 
>> language will see char[] and string, and wonder which should be used 
>> when. I can't think of any consistent understandable rule for that. So 
>> it just winds up being wishy-washy. Adding more names into the global 
>> space (which is what names in object.d are) should be done extremely 
>> conservatively.
> 
> And yet we have "toString" and not "toCharArray" or "toUTF"!

True, and some have called for renaming char to utf8. While that would 
be technically more correct (as toUTF would be, too), it just looks awful.

I suppose that since I grew up with char* meaning string, using char[] 
seems perfectly natural. I tried typedef'ing char* to string now and 
then, but always wound up going back to just using char*.

> And we still have the "printf" in object.d too!

I know many feel that printf doesn't belong there. It certainly isn't 
there for purity or consistency. It's there purely (!) for the 
convenience of writing short quickie programs. I tend to use it for 
quick debugging test cases, because it doesn't rely on the rest of D 
working.

>> If someone wants to use the string alias as their personal or company 
>> style, I have no issue with that, as other people *do* think differently 
>> than me (which is abundantly clear here!).
> 
> I'll revert Build to string again as it is a lot easier to read. It started
> out that way but I converted it to char[] to appease you (why I thought you
> need appeasing is lost though). :-)

No, you certainly don't need to appease me! I do care about maintaining 
a reasonably consistent style in Phobos, but I don't believe a language 
should enforce a particular style beyond the standard library. Viva la 
difference.

P.S. I did say to not 'enforce', but that doesn't mean I am above 
recommending a particular style, as in 
http://www.digitalmars.com/d/dstyle.html



More information about the Digitalmars-d mailing list