What are delimited strings good for?
Jonathan M Davis
jmdavisProg at gmx.com
Sun Apr 10 13:51:12 PDT 2011
> On 4/10/11 11:03 AM, simendsjo wrote:
> > Ref http://digitalmars.com/d/2.0/lex.html
> >
> > What are some possible use cases for delimited strings?
> > What is solved by having this in the language?
>
> Readability.
>
> auto s = "This is 'something' that \"could\" have been made easier to
> read";
>
> auto t = q"[This is 'something' that "could" have been made easier to
> read]";
>
> (although I don't like that you have to type two chars after the q. In
> ruby you'd write
>
> %q(This is 'something' that "could have been made easier to read)
>
> )
WYSIWYG strings already give you that with everything but backticks. So, other
than strings with both backticks and quotes in them, I don't see much point to
delimited strings. The string that you gave could have been done with
auto t = `This is 'something' that "could" have been made easier to read`;
If that had been `something instead of 'something, _then_ the delimited string
becomes useful, but given how rarely backticks are needed, it does seem rather
odd to have delimited strings just for that. So, I definitely have to wonder
why they exist.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list