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

WebFreak001 d.forum at webfreak.org
Thu Dec 9 07:47:40 UTC 2021


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.


More information about the Digitalmars-d mailing list