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

Q. Schroll qs.il.paperinik at gmail.com
Mon Dec 13 15:42:43 UTC 2021


On Sunday, 12 December 2021 at 20:55:49 UTC, Ola Fosheim Grøstad 
wrote:
> On Sunday, 12 December 2021 at 19:44:17 UTC, Q. Schroll wrote:
>> On Thursday, 9 December 2021 at 16:30:28 UTC, Ola Fosheim 
>> Grøstad wrote:
>>> I would not recommend weaker typing, as it would be trivial 
>>> to get stronger typing by simply supporting ```f"this $will 
>>> become a string"``` and ```i"this $will become a list"```.
>>
>> That would have the problem that confusing `i""` and `f""` 
>> could lead to SQL injections and related problems. The 
>> improvement over using `i"".text` is almost nonexistent.
>
> How could you confuse them?

In cases like this, for example?
```D
void func(string str);
void func(Is...)(Is interpString)
   if (isInterpString!Is);

string value = "bla";
func(f"some $bla bla"); // calls first one
func(i"some $bla bla"); // calls second one
```
If I understand your suggestion correctly, both would compile, 
but be handled differently. It's a one-keystroke difference and 
people will conflate `i""` and `f""` for sure and it could lead 
to serious vulnerabilities. Carefully crafted `func` can make one 
an error, but not so carefully made ones might not. It becomes a 
hard(er)-to-use-correctly issue.

> The type system would prevent it.

Only if it is assisted by the programmer. If the type system 
could distinguish all the cases, i.e. there is no case where 
`f""` and `i""` work both, you wouldn't need the distinction in 
the first place. One could do a best effort approach, but I agree 
that weak typing is bad.


More information about the Digitalmars-d mailing list