The state of string interpolation

o o at o.o
Thu Dec 6 00:10:56 UTC 2018


I really wish that D had string interpolation, and I can see that 
a ton of other people also do. String interpolation has been 
brought up before, but it has been ignored/put down every time. 
Jonathan Marler even created a Pull Request 
(https://github.com/dlang/dmd/pull/7988) to add this feature, but 
he ended up closing it because it was getting nowhere. The excuse 
that keeps being given for not adding this feature is something 
along the lines of "There are ways to work around this, so it is 
unnecessary to add it". If this is the case, then why do people 
keep on requesting it again and again? Here are just some cases 
of other people asking for string interpolation:

- https://forum.dlang.org/thread/c2q7dt$67t$1@digitaldaemon.com
- 
https://forum.dlang.org/thread/qpuxtedsiowayrhgyell@forum.dlang.org
- 
https://forum.dlang.org/thread/ncwpezwlgeajdrigegee@forum.dlang.org
And there are 2 closed PRs for this:
- https://github.com/dlang/dmd/pull/6703
- https://github.com/dlang/dmd/pull/7988

In my opinion, having a sizable amount of people request a 
feature (about 100 out of 280 as of The State of D Survey 
[https://dlang.typeform.com/report/H1GTak/PY9NhHkcBFG0t6ig]) is a 
good enough to realize that maybe we should start thinking of 
adding it to the language.

I understand that this may involve a DIP process, which takes 
time. Therefore I am willing to offer up $100 to someone if they 
are willing to go through the DIP process for string 
interpolation.

And please don't mention Phobos' sorry excuse for string 
interpolation:
"a is: %s, b is: %s, sum is %s.".format(a, b, a + b)
Is no better than
"a is: "~a.to!string~"b is: "~b.to!string~" and the sum is: 
"~(a+b).to!string~"."

This is just so much more readable, and maintainable:
"a is: ${a}, b is: ${b}, and the sum is: ${a+b}."

And, it gets even more readable with syntax highlighting: 
https://i.imgur.com/Bz79vtV.png

So please, what I am asking is that we start to *seriously* 
consider adding string interpolation to D. Thanks for taking the 
time to read this!


More information about the Digitalmars-d mailing list