On Thursday, 27 February 2020 at 09:30:30 UTC, Walter Bright wrote:
You can make it behave like all those other languages simply with:

    f(format("hello $a"));

At that point, it begs the question of why even bother having string interpolation.

I'd like to imagine that most newcomers/returning veterans of D would see "D has string interpolation!" and then expect it to work similar to how it does in most other languages.

They'd expect f(format("hello %s", a)) to be replaced by a much more compact f("hello $a"), instead of some D-ism take on interpolation that doesn't really provide much in the way of the main use of the feature: easily creating formatted strings.

People more used to D will likely go "Oh, that's kind of weird yet cool" once they learn what it lowers down to, yet newcomers who aren't too caught up with the language's features will simply be annoyed and confused that it 'feels' (not necessarily is) more complicated than needed.

It appears the main focus in these dicussions are "What super super cool and niche (in comparison to string formatting) things can we do with this feature!" while mostly blind-siding that it's generally an easy-to-use, easy-to-understand feature in other languages.

Similarly, as far as I can tell even with the adjustment of making these strings their own special type, something as simple (for other languages as):

```
void f(string a, string b)
{ /*...*/ }

int foo = 20;
string bar = "lalafell";
f(i"You are a foo($foo)", i"I am not a $bar");
```

Isn't easily achieved without use of an extra helper function such as i"...".format or .str, etc.

My view on it is that this is generally a QoL feature, which some languages (C#, Swift) have had success in keeping the basic principle of interpolation while also granting user code the power to perform some of the things being suggested (e.g. In C#, string interpolation works as-expected, yet check out functions such as FromSqlInterpolated[1] which can directly access the format string & values simply by taking a special `FormattableString` type)

To be honest, if D's take on interpolation makes people scratch their head in confusion at the most basic use case, then it's probably not even worth adding to the language.

[1] https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationalqueryableextensions.fromsqlinterpolated?view=efcore-3.1

Reply via email to