[OT] C# can do all the interpolated strings now

Steven Schveighoffer schveiguy at gmail.com
Thu Dec 9 15:47:11 UTC 2021


On 12/9/21 10:20 AM, WebFreak001 wrote:
> On Thursday, 9 December 2021 at 15:16:40 UTC, WebFreak001 wrote:
>> On Thursday, 9 December 2021 at 14:57:25 UTC, Steven Schveighoffer wrote:
>>> [...]
>>>
>>> i.e. this is practically identical to:
>>>
>>> ```d
>>> sql(i"SELECT x,y,z FROM $something WHERE $condition");
>>> ```
>>>
>>> Or even:
>>>
>>> ```d
>>> i"SELECT x,y,z FROM $something WHERE $condition".sql;
>>> ```
>>>
>>
>> [...]
> 
> and I want to add, this is the super rare case:
> 
> ```d
> foo(i"hello $name")
> ```

I disagree. I find that the non-rare case. This is what I'm looking for. 
The interesting case is not some specialized function that transforms 
the parameters into a string in a specific way, but one that accepts the 
parameters as-is and works with them directly.

> this is the much more common case:
> 
> ```d
> foo(i"hello $name".text)
> // or
> foo(text(i"hello $name"))
> ```

In my original DIP, I tried to handle both cases, `foo(i"hello $name")` 
for `foo(string)` would work. It's a messy situation, and I think it's 
the reason there was so much opposition.

Having to type `text` or whatever is a reasonable compromise.

> 
> I don't think the common case should always have this extra `i` prefix + 
> needed function calling parentheses or ufcs dot. Just only writing 
> `text"hello $name"` is shorter, easier to type, better to read.

Note that the string interpolation proposal does not preclude this 
possibility happening later.

Reasonable people can disagree whether this "makes the feature" or not 
though.

-Steve


More information about the Digitalmars-d mailing list