String interpolation, after a healthy debate on discord

Abdulhaq alynch4047 at gmail.com
Tue Dec 14 15:47:59 UTC 2021


On Thursday, 9 December 2021 at 21:06:11 UTC, WebFreak001 wrote:
> We had an argument on the discord about the 
> [YAIDIP](https://github.com/John-Colvin/YAIDIP) proposal and a

To a give another POV, from a polyglot background, I'd say there 
is a statement in the YAIDIP which is incorrect and somewhat 
skews the rest of the argument:

```The simplest use case of interpolated strings, and the most 
likely to be encountered in practice, is as argument to functions 
such as writeln, text, writefln, or format:```

Surely the simplest use case, and most likely to be encountered, 
is simply to build a well formatted string from a blend of string 
literals and local variables:

```
int x = 42;
auto s = i"Let's interpolate $x!"
```

where s would be of string type.

I use interpolated strings in numerous languages and I do so to 
present a clear expression to the reading developer of the 
intended format of the final string, and to keep the code tidy. 
In fact, I code like above specifically to avoid passing messy 
expressions as arguments to a following function call.

I can see the power and attraction of the proposed design, but it 
has to be weighed against a syntax that satisfies the principle 
of least astonishment, as also identified in the same DIP.

I'm also thinking that if tuples were more fully integrated and 
rationalised in the language then the benefits offered by this 
DIP regarding passing argument lists to string handling functions 
could be achieved in some other way using syntactically 
convenient unpacking of tuples into argument lists, but it's been 
a long time now since I used D in anger so if this part of my 
argument is just noise then... ignore it :-)


More information about the Digitalmars-d mailing list