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

bauss jj_1337 at live.dk
Thu Dec 9 09:48:35 UTC 2021

On Thursday, 9 December 2021 at 07:47:40 UTC, WebFreak001 wrote:
> On Wednesday, 8 December 2021 at 22:10:32 UTC, Steven 
> Schveighoffer wrote:
>> On 12/8/21 4:31 PM, kdevel wrote:
>>> [...]
>> Both are readable, though I'd argue that for this particular 
>> example, the usage of `$(expr)` for syntax makes things 
>> complex to read (syntax highlighting should help). In our DIP 
>> we used ${expr}, which for SQL would be more readable, but 
>> might look worse for things like code mixins.
>> But there are plenty of examples where the string-blueprint 
>> form is less readable (the INSERT form where you specify 
>> fields first, and then parameters later is kind of a terrible 
>> syntax to begin with).
>> e.g. (from a real line of code in my codebase):
>> ```d
>> conn.exec("UPDATE organization SET loc_lat = ?, loc_lon = ? 
>> WHERE id = ?", loc_latitude, loc_longitude, id);
>> // compare to:
>> conn.exec(i"UPDATE organization SET loc_lat = $loc_latitude, 
>> loc_lon = $loc_longitude WHERE id = $id");
>> ```
>> -Steve
> I wonder why are most languages using $ or {}? What's the 
> advantage over `\(...)`?
> With `\` we have the advantage of not reserving another special 
> character in strings - we already use `\`! It'd be fully 
> backwards compatible even without the i prefix.
> Swift does this too.

I think it's because the idea for interpolated strings evolved 
from template engines / perl's variable interpolation (which sort 
of is string interpolation) where syntaxes for values etc. are 
commonly using {x} {{x}} $x etc.

So it's probably just to keep it similar to that, as those are 
familiar syntaxes and has been through decades.

Doesn't mean it's the best or can't be improved, but sometimes 
introducing new syntaxes etc. also introduces new complexities 
and additional learning curve.

More information about the Digitalmars-d mailing list