August 07, 2003 Re: String literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to j anderson | "j anderson" <anderson@badmama.com.au.REMOVE> wrote in message news:bgte8b$2cs$1@digitaldaemon.com... > > "Mark Evans" <Mark_member@pathlink.com> wrote in message news:bg6rkb$2k4p$1@digitaldaemon.com... > > > > OK, Walter, here is my final answer. Do not use @ even though C# uses it. > That > > was a bad choice on Microsoft's part. They really should have known > better. > > Too many preprocessors and languages use @ for special purposes. Think > SWIG, > > JavaDoc, etc. > > > > Use r"string"r or raw"string"raw. The advantage here is that you can > later > > define new types of strings with a new letter (Unicode? a string of bits, > > b"101010101111111000000" or hexadecimal bit groups, > x"ABCD12340000FFFF11111"?). > > So in a sense it's extensible and future-proof. This syntax is also > reminiscent > > of C's numeric prefix and suffix notations, 0xABCD, 0b1010, 1.234L, etc. > > > > The numeric string concept is convenient for static pre-assignment of > memory. > > The alternatives in C are not pretty: arrays of smaller things (comma, > comma, > > comma, comma, another comma,...) or an unreadable string > ("#$~H*G_#@jdkBG$*&"). > > So this notation is extra candy on top for embedded programming work. > > > > The redundant closing letter is optional but recommended. It solves the meta-escape problem very cleanly. (Actually it's dumbed-down XML.) The b > and x > > variants would not require closing letters, as their contents are > intrinsically > > limited. Whitespace should be allowed in them of course, x"ABCD 1234 > FF00". > > > > Mark > > > > I came to a simular conclusion. The there suggested syntaxes (I haven't read > all the replies) would make it much harder for the transition from C to D. Explaining that a character is put in front of the quote is easier then explaining that you need to use a particular symbol instead of quote. > > There may be some use for this syntax on array's as well. > > u{10,12,16}; //enforce unsigned. > r{10,12,16}; //read only. > o{10,12,16}; //ordered. > fi{c:\data.txt}; //file to import integer array from. > > I can't think of anything *good* right now, but it's an option for latter down the track. > Another idea would be {" "} The {" "} would imply it's an array of chars. Of course " would still need to be overloaded, but that could be done with a double quote. i.e. char a[] = {"This is an in-text quote ""."}; or parhaps even better char a[] = {"This is an in-text quote ", 34, "."); char a[] = {"This is an in-text quote ", '"', "."); All would print This is an in-text quote ". Although I still don't mind the append char "r" to front of string technique. - J Anderson |
Copyright © 1999-2021 by the D Language Foundation