The state of string interpolation
o
o at o.o
Mon Dec 10 01:54:05 UTC 2018
On Thursday, 6 December 2018 at 16:19:12 UTC, Steven
Schveighoffer wrote:
> On 12/6/18 4:01 AM, Dennis wrote:
>> On Thursday, 6 December 2018 at 02:14:12 UTC, Neia Neutuladh
>> wrote:
>>> However, that would also force druntime to include formatting
>>> code that it currently lacks.
>>
>> Jonathan Marler's implementation [1] has a really nice
>> approach of lowering interpolated strings to tuples. You can
>> pass it to variadic functions like `writeln` or `text` and
>> bring your own formatting / memory allocation schemes, giving
>> better performance and flexibility.
>>
>> [1] https://github.com/dlang/dmd/pull/7988
>
> I supported the concept[1] back when I read it from Dmitry
> Olshansky[2].
>
> If I had known about the debate on the PR I would have jumped
> in. But I don't have much to add. All that really dictates my
> views is the experience I've had with other languages. However,
> none of those other languages have the same concept that I know
> of -- they basically just create a string with toString-ing the
> interpolations.
>
> With the concept of lowering to a tuple, I'd love to use such a
> thing for database queries.
>
> For instance:
>
> db.exec("UPDATE Foo SET a = ?, b = ?, c = ?, d = ? WHERE id =
> ?", aval, bval, cval, dval, id);
>
> vs.
>
> db.exec(i"UPDATE Foo SET a = $aval, b = $bval, c = $cval, d =
> $dval WHERE id = $id");
>
> The mixin/library solution is much less approachable. What's
> awesome about the language solution is that it just works
> without much extra understanding and verbosity, and need for
> using mixins. mixins are cool, but are best tucked away behind
> templates or generative functions. They shouldn't seen much in
> user code. Saying we should use a library solution for this is
> like saying we can replace foreach usage with a library foreach
> that lowers to some for-loop and explicit delegates (or maybe a
> mixin?). Yes, it could be done. No, it shouldn't be done. This
> is one of those types of syntax sugar that should not be
> ignored.
>
> +1000 from me, I'd love to see the PR merged, or the DIP
> created, whatever needs to happen.
>
> -Steve
>
> [1] https://forum.dlang.org/post/odb9hk$2jqm$1@digitalmars.com
> [2] https://forum.dlang.org/post/ocut06$261n$1@digitalmars.com
Can you add some examples/explanations about the database
querying to the DIP?
More information about the Digitalmars-d
mailing list